rename printf -> catf; no other changes

This commit is contained in:
Eric House 2013-10-09 20:20:45 -07:00
parent 6cbfc03228
commit bb246fd7e7
7 changed files with 100 additions and 100 deletions

View file

@ -581,7 +581,7 @@ cmd_acks( int socket, const char* cmd, int argc, gchar** argv )
}; };
StrWPF help; StrWPF help;
for ( size_t ii = 0; ii < VSIZE(strs); ++ii ) { for ( size_t ii = 0; ii < VSIZE(strs); ++ii ) {
help.printf( strs[ii], cmd ); help.catf( strs[ii], cmd );
} }
send( socket, help.c_str(), help.size(), 0 ); send( socket, help.c_str(), help.size(), 0 );
} }
@ -630,7 +630,7 @@ cmd_devs( int socket, const char* cmd, int argc, gchar** argv )
} }
} else { } else {
int deleted = DevMgr::Get()->forgetDevices( devids ); int deleted = DevMgr::Get()->forgetDevices( devids );
result.printf( "Deleted %d devices\n", deleted ); result.catf( "Deleted %d devices\n", deleted );
} }
} }
} else if ( 0 == strcmp( "ping", arg1 ) ) { } else if ( 0 == strcmp( "ping", arg1 ) ) {
@ -655,10 +655,10 @@ cmd_devs( int socket, const char* cmd, int argc, gchar** argv )
if ( 0 != devid ) { if ( 0 != devid ) {
if ( post_message( devid, unesc, onAckProc, if ( post_message( devid, unesc, onAckProc,
(void*)socket ) ) { (void*)socket ) ) {
result.printf( "posted message: %s\n", unesc ); result.catf( "posted message: %s\n", unesc );
} else { } else {
result.printf( "unable to post; does " result.catf( "unable to post; does dev %d exist\n",
"dev %d exist\n", devid ); devid );
} }
} }
} }
@ -684,7 +684,7 @@ cmd_devs( int socket, const char* cmd, int argc, gchar** argv )
StrWPF help; StrWPF help;
for ( size_t ii = 0; ii < VSIZE(strs); ++ii ) { for ( size_t ii = 0; ii < VSIZE(strs); ++ii ) {
help.printf( strs[ii], cmd ); help.catf( strs[ii], cmd );
} }
send( socket, help.c_str(), help.size(), 0 ); send( socket, help.c_str(), help.size(), 0 );
} }

View file

@ -142,7 +142,7 @@ DBMgr::FindGameFor( const char* connName, char* cookieBuf, int bufLen,
"AND %d = seeds[%d] AND 'A' = ack[%d] " "AND %d = seeds[%d] AND 'A' = ack[%d] "
; ;
StrWPF query; StrWPF query;
query.printf( fmt, connName, nPlayersS, seed, hid, hid ); query.catf( fmt, connName, nPlayersS, seed, hid, hid );
logf( XW_LOGINFO, "query: %s", query.c_str() ); logf( XW_LOGINFO, "query: %s", query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -171,7 +171,7 @@ DBMgr::FindGame( const char* connName, char* cookieBuf, int bufLen,
// " LIMIT 1" // " LIMIT 1"
; ;
StrWPF query; StrWPF query;
query.printf( fmt, connName ); query.catf( fmt, connName );
logf( XW_LOGINFO, "query: %s", query.c_str() ); logf( XW_LOGINFO, "query: %s", query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -199,7 +199,7 @@ DBMgr::FindPlayer( DevIDRelay relayID, AddrInfo::ClientToken token,
const char* fmt = const char* fmt =
"SELECT connName FROM %s WHERE %d = ANY(devids) AND %d = ANY(tokens)"; "SELECT connName FROM %s WHERE %d = ANY(devids) AND %d = ANY(tokens)";
StrWPF query; StrWPF query;
query.printf( fmt, GAMES_TABLE, relayID, token ); query.catf( fmt, GAMES_TABLE, relayID, token );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
int nTuples = PQntuples( result ); int nTuples = PQntuples( result );
@ -217,8 +217,8 @@ DBMgr::FindPlayer( DevIDRelay relayID, AddrInfo::ClientToken token,
fmt = "SELECT seeds[%d] FROM %s WHERE connname = '%s' " fmt = "SELECT seeds[%d] FROM %s WHERE connname = '%s' "
"AND devids[%d] = %d AND tokens[%d] = %d"; "AND devids[%d] = %d AND tokens[%d] = %d";
StrWPF query; StrWPF query;
query.printf( fmt, hid, GAMES_TABLE, name, query.catf( fmt, hid, GAMES_TABLE, name,
hid, relayID, hid, token ); hid, relayID, hid, token );
result = PQexec( getThreadConn(), query.c_str() ); result = PQexec( getThreadConn(), query.c_str() );
int nTuples2 = PQntuples( result ); int nTuples2 = PQntuples( result );
for ( int jj = 0; jj < nTuples2; ++jj ) { for ( int jj = 0; jj < nTuples2; ++jj ) {
@ -245,9 +245,9 @@ DBMgr::FindRelayIDFor( const char* connName, HostID hid,
{ {
DevIDRelay devID = DEVID_NONE; DevIDRelay devID = DEVID_NONE;
StrWPF query; StrWPF query;
query.printf( "SELECT devids[%d] FROM " GAMES_TABLE " WHERE " query.catf( "SELECT devids[%d] FROM " GAMES_TABLE " WHERE "
"connname = '%s' AND seeds[%d] = %d", hid, "connname = '%s' AND seeds[%d] = %d", hid,
connName, hid, seed ); connName, hid, seed );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
int nTuples = PQntuples( result ); int nTuples = PQntuples( result );
assert( nTuples <= 1 ); assert( nTuples <= 1 );
@ -354,7 +354,7 @@ DBMgr::AllDevsAckd( const char* const connName )
const char* cmd = "SELECT ntotal=sum_array(nperdevice) AND 'A'=ALL(ack) from " GAMES_TABLE const char* cmd = "SELECT ntotal=sum_array(nperdevice) AND 'A'=ALL(ack) from " GAMES_TABLE
" WHERE connName='%s'"; " WHERE connName='%s'";
StrWPF query; StrWPF query;
query.printf( cmd, connName ); query.catf( cmd, connName );
logf( XW_LOGINFO, "query: %s", query.c_str() ); logf( XW_LOGINFO, "query: %s", query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -436,10 +436,10 @@ DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host,
{ {
// First update the existing // First update the existing
StrWPF query; StrWPF query;
query.printf( "UPDATE " DEVICES_TABLE " SET " query.catf( "UPDATE " DEVICES_TABLE " SET "
"devTypes = array_prepend( %d, devTypes), " "devTypes = array_prepend( %d, devTypes), "
"devids = array_prepend('%s', devids), ", "devids = array_prepend('%s', devids), ",
host->m_devIDType, host->m_devIDString.c_str() ); host->m_devIDType, host->m_devIDString.c_str() );
formatUpdate( query, true, desc, clientVersion, model, osVers, relayID ); formatUpdate( query, true, desc, clientVersion, model, osVers, relayID );
execSql( query ); execSql( query );
@ -454,13 +454,13 @@ DBMgr::UpdateDevice( DevIDRelay relayID, const char* const desc,
bool exists = !check; bool exists = !check;
if ( !exists ) { if ( !exists ) {
StrWPF test; StrWPF test;
test.printf( "id = %d", relayID ); test.catf( "id = %d", relayID );
exists = 1 <= getCountWhere( DEVICES_TABLE, test ); exists = 1 <= getCountWhere( DEVICES_TABLE, test );
} }
if ( exists ) { if ( exists ) {
StrWPF query; StrWPF query;
query.printf( "UPDATE " DEVICES_TABLE " SET " ); query.catf( "UPDATE " DEVICES_TABLE " SET " );
formatUpdate( query, false, desc, clientVersion, model, osVers, relayID ); formatUpdate( query, false, desc, clientVersion, model, osVers, relayID );
execSql( query ); execSql( query );
} }
@ -479,21 +479,21 @@ DBMgr::formatUpdate( StrWPF& query, bool append, const char* const desc,
const char* const osVers, DevIDRelay relayID ) const char* const osVers, DevIDRelay relayID )
{ {
if ( append ) { if ( append ) {
query.printf( "mtimes=array_prepend('now', mtimes)" ); // FIXME: too many query.catf( "mtimes=array_prepend('now', mtimes)" ); // FIXME: too many
} else { } else {
query.printf( "mtimes[1]='now'" ); query.catf( "mtimes[1]='now'" );
} }
if ( NULL != desc && '\0' != desc[0] ) { if ( NULL != desc && '\0' != desc[0] ) {
query.printf( ", clntVers=%d, versDesc='%s'", clientVersion, desc ); query.catf( ", clntVers=%d, versDesc='%s'", clientVersion, desc );
} }
if ( NULL != model && '\0' != model[0] ) { if ( NULL != model && '\0' != model[0] ) {
query.printf( ", model='%s'", model ); query.catf( ", model='%s'", model );
} }
if ( NULL != osVers && '\0' != osVers[0] ) { if ( NULL != osVers && '\0' != osVers[0] ) {
query.printf( ", osvers='%s'", osVers ); query.catf( ", osvers='%s'", osVers );
} }
query.printf( " WHERE id = %d", relayID ); query.catf( " WHERE id = %d", relayID );
} }
HostID HostID
@ -528,22 +528,22 @@ DBMgr::AddToGame( const char* connName, HostID curID, int clientVersion,
assert( newID <= 4 ); assert( newID <= 4 );
StrWPF query; StrWPF query;
query.printf( "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d," query.catf( "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d,"
" clntVers[%d] = %d, seeds[%d] = %d, addrs[%d] = \'%s\', ", " clntVers[%d] = %d, seeds[%d] = %d, addrs[%d] = \'%s\', ",
newID, nToAdd, newID, clientVersion, newID, seed, newID, newID, nToAdd, newID, clientVersion, newID, seed, newID,
inet_ntoa( addr->sin_addr() ) ); inet_ntoa( addr->sin_addr() ) );
if ( DEVID_NONE != devID ) { if ( DEVID_NONE != devID ) {
query.printf( "devids[%d] = %d, ", newID, devID ); query.catf( "devids[%d] = %d, ", newID, devID );
} }
query.printf( " tokens[%d] = %d, mtimes[%d]='now', ack[%d]=\'%c\'" query.catf( " tokens[%d] = %d, mtimes[%d]='now', ack[%d]=\'%c\'"
" WHERE connName = '%s'", newID, addr->clientToken(), " WHERE connName = '%s'", newID, addr->clientToken(),
newID, newID, ackd?'A':'a', connName ); newID, newID, ackd?'A':'a', connName );
// Update the devices table too. Eventually the clntVers field of the // Update the devices table too. Eventually the clntVers field of the
// games table should go away. // games table should go away.
if ( DEVID_NONE != devID ) { if ( DEVID_NONE != devID ) {
query.printf( "; UPDATE " DEVICES_TABLE " SET clntVers = %d" query.catf( "; UPDATE " DEVICES_TABLE " SET clntVers = %d"
" WHERE id = %d", clientVersion, devID ); " WHERE id = %d", clientVersion, devID );
} }
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
@ -558,7 +558,7 @@ DBMgr::NoteAckd( const char* const connName, HostID id )
const char* fmt = "UPDATE " GAMES_TABLE " SET ack[%d]='A'" const char* fmt = "UPDATE " GAMES_TABLE " SET ack[%d]='A'"
" WHERE connName = '%s'"; " WHERE connName = '%s'";
StrWPF query; StrWPF query;
query.printf( fmt, id, connName ); query.catf( fmt, id, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
execSql( query ); execSql( query );
@ -570,7 +570,7 @@ DBMgr::RmDeviceByHid( const char* connName, HostID hid )
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = 0, " const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = 0, "
"seeds[%d] = 0, ack[%d]='-', mtimes[%d]='now' WHERE connName = '%s'"; "seeds[%d] = 0, ack[%d]='-', mtimes[%d]='now' WHERE connName = '%s'";
StrWPF query; StrWPF query;
query.printf( fmt, hid, hid, hid, hid, connName ); query.catf( fmt, hid, hid, hid, hid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
return execSql( query ); return execSql( query );
@ -585,7 +585,7 @@ DBMgr::HIDForSeed( const char* const connName, unsigned short seed )
" WHERE connName = '%s'" " WHERE connName = '%s'"
" AND %d = ANY(seeds)"; " AND %d = ANY(seeds)";
StrWPF query; StrWPF query;
query.printf( fmt, connName, seed ); query.catf( fmt, connName, seed );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
if ( 1 == PQntuples( result ) ) { if ( 1 == PQntuples( result ) ) {
@ -632,7 +632,7 @@ DBMgr::HaveDevice( const char* connName, HostID hid, int seed )
const char* fmt = "SELECT * from " GAMES_TABLE const char* fmt = "SELECT * from " GAMES_TABLE
" WHERE connName = '%s' AND seeds[%d] = %d"; " WHERE connName = '%s' AND seeds[%d] = %d";
StrWPF query; StrWPF query;
query.printf( fmt, connName, hid, seed ); query.catf( fmt, connName, hid, seed );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
found = 1 == PQntuples( result ); found = 1 == PQntuples( result );
@ -646,7 +646,7 @@ DBMgr::AddCID( const char* const connName, CookieID cid )
const char* fmt = "UPDATE " GAMES_TABLE " SET cid = %d " const char* fmt = "UPDATE " GAMES_TABLE " SET cid = %d "
" WHERE connName = '%s' AND cid IS NULL"; " WHERE connName = '%s' AND cid IS NULL";
StrWPF query; StrWPF query;
query.printf( fmt, cid, connName ); query.catf( fmt, cid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
bool result = execSql( query ); bool result = execSql( query );
@ -660,7 +660,7 @@ DBMgr::ClearCID( const char* connName )
const char* fmt = "UPDATE " GAMES_TABLE " SET cid = null " const char* fmt = "UPDATE " GAMES_TABLE " SET cid = null "
"WHERE connName = '%s'"; "WHERE connName = '%s'";
StrWPF query; StrWPF query;
query.printf( fmt, connName ); query.catf( fmt, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
execSql( query ); execSql( query );
@ -674,7 +674,7 @@ DBMgr::RecordSent( const char* const connName, HostID hid, int nBytes )
" nsents[%d] = nsents[%d] + %d, mtimes[%d] = 'now'" " nsents[%d] = nsents[%d] + %d, mtimes[%d] = 'now'"
" WHERE connName = '%s'"; " WHERE connName = '%s'";
StrWPF query; StrWPF query;
query.printf( fmt, hid, hid, nBytes, hid, connName ); query.catf( fmt, hid, hid, nBytes, hid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
execSql( query ); execSql( query );
@ -685,10 +685,10 @@ DBMgr::RecordSent( const int* msgIDs, int nMsgIDs )
{ {
if ( nMsgIDs > 0 ) { if ( nMsgIDs > 0 ) {
StrWPF query; StrWPF query;
query.printf( "SELECT connname,hid,sum(msglen)" query.catf( "SELECT connname,hid,sum(msglen)"
" FROM " MSGS_TABLE " WHERE id IN (" ); " FROM " MSGS_TABLE " WHERE id IN (" );
for ( int ii = 0; ; ) { for ( int ii = 0; ; ) {
query.printf( "%d", msgIDs[ii] ); query.catf( "%d", msgIDs[ii] );
if ( ++ii == nMsgIDs ) { if ( ++ii == nMsgIDs ) {
break; break;
} else { } else {
@ -719,7 +719,7 @@ DBMgr::RecordAddress( const char* const connName, HostID hid,
" WHERE connName = '%s'"; " WHERE connName = '%s'";
StrWPF query; StrWPF query;
char* ntoa = inet_ntoa( addr->sin_addr() ); char* ntoa = inet_ntoa( addr->sin_addr() );
query.printf( fmt, hid, ntoa, connName ); query.catf( fmt, hid, ntoa, connName );
logf( XW_LOGVERBOSE0, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGVERBOSE0, "%s: query: %s", __func__, query.c_str() );
execSql( query ); execSql( query );
@ -731,7 +731,7 @@ DBMgr::GetPlayerCounts( const char* const connName, int* nTotal, int* nHere )
const char* fmt = "SELECT ntotal, sum_array(nperdevice) FROM " GAMES_TABLE const char* fmt = "SELECT ntotal, sum_array(nperdevice) FROM " GAMES_TABLE
" WHERE connName = '%s'"; " WHERE connName = '%s'";
StrWPF query; StrWPF query;
query.printf( fmt, connName ); query.catf( fmt, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -748,7 +748,7 @@ DBMgr::KillGame( const char* const connName, int hid )
" nperdevice[%d] = - nperdevice[%d]" " nperdevice[%d] = - nperdevice[%d]"
" WHERE connName = '%s'"; " WHERE connName = '%s'";
StrWPF query; StrWPF query;
query.printf( fmt, hid, hid, connName ); query.catf( fmt, hid, hid, connName );
execSql( query ); execSql( query );
} }
@ -771,7 +771,7 @@ DBMgr::PublicRooms( int lang, int nPlayers, int* nNames, string& names )
" AND nTotal = %d"; " AND nTotal = %d";
StrWPF query; StrWPF query;
query.printf( fmt, lang, nPlayers ); query.catf( fmt, lang, nPlayers );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -796,7 +796,7 @@ DBMgr::TokenFor( const char* const connName, int hid, DevIDRelay* devid,
const char* fmt = "SELECT tokens[%d], devids[%d] FROM " GAMES_TABLE const char* fmt = "SELECT tokens[%d], devids[%d] FROM " GAMES_TABLE
" WHERE connName='%s'"; " WHERE connName='%s'";
StrWPF query; StrWPF query;
query.printf( fmt, hid, hid, connName ); query.catf( fmt, hid, hid, connName );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
if ( 1 == PQntuples( result ) ) { if ( 1 == PQntuples( result ) ) {
AddrInfo::ClientToken token_tmp = atoi( PQgetvalue( result, 0, 0 ) ); AddrInfo::ClientToken token_tmp = atoi( PQgetvalue( result, 0, 0 ) );
@ -851,7 +851,7 @@ DBMgr::readArray( const char* const connName, const char* column, int arr[] ) /
const char* fmt = "SELECT %s FROM " GAMES_TABLE " WHERE connName='%s'"; const char* fmt = "SELECT %s FROM " GAMES_TABLE " WHERE connName='%s'";
StrWPF query; StrWPF query;
query.printf( fmt, column, connName ); query.catf( fmt, column, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -868,7 +868,7 @@ DBMgr::getDevID( const char* connName, int hid )
DevIDRelay devID = DEVID_NONE; DevIDRelay devID = DEVID_NONE;
const char* fmt = "SELECT devids[%d] FROM " GAMES_TABLE " WHERE connName='%s'"; const char* fmt = "SELECT devids[%d] FROM " GAMES_TABLE " WHERE connName='%s'";
StrWPF query; StrWPF query;
query.printf( fmt, hid, connName ); query.catf( fmt, hid, connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -891,13 +891,13 @@ DBMgr::getDevID( const DevID* devID )
DevIDRelay cur = devID->asRelayID(); DevIDRelay cur = devID->asRelayID();
if ( DEVID_NONE != cur ) { if ( DEVID_NONE != cur ) {
const char* fmt = "SELECT id FROM " DEVICES_TABLE " WHERE id=%d"; const char* fmt = "SELECT id FROM " DEVICES_TABLE " WHERE id=%d";
query.printf( fmt, cur ); query.catf( fmt, cur );
} }
} else if ( 0 < devID->m_devIDString.size() ) { } else if ( 0 < devID->m_devIDString.size() ) {
query.printf( "SELECT id FROM " DEVICES_TABLE query.catf( "SELECT id FROM " DEVICES_TABLE
" WHERE devtypes[1]=%d and devids[1] = '%s'" " WHERE devtypes[1]=%d and devids[1] = '%s'"
" ORDER BY ctime DESC LIMIT 1", " ORDER BY ctime DESC LIMIT 1",
devIDType, devID->m_devIDString.c_str() ); devIDType, devID->m_devIDString.c_str() );
} }
if ( 0 < query.size() ) { if ( 0 < query.size() ) {
@ -927,12 +927,12 @@ int
DBMgr::CountStoredMessages( const char* const connName, int hid ) DBMgr::CountStoredMessages( const char* const connName, int hid )
{ {
StrWPF test; StrWPF test;
test.printf( "connname = '%s'", connName ); test.catf( "connname = '%s'", connName );
#ifdef HAVE_STIME #ifdef HAVE_STIME
test.printf( " AND stime = 'epoch'" ); test.catf( " AND stime = 'epoch'" );
#endif #endif
if ( hid != -1 ) { if ( hid != -1 ) {
test.printf( " AND hid = %d", hid ); test.catf( " AND hid = %d", hid );
} }
return getCountWhere( MSGS_TABLE, test ); return getCountWhere( MSGS_TABLE, test );
@ -948,9 +948,9 @@ int
DBMgr::CountStoredMessages( DevIDRelay relayID ) DBMgr::CountStoredMessages( DevIDRelay relayID )
{ {
StrWPF test; StrWPF test;
test.printf( "devid = %d", relayID ); test.catf( "devid = %d", relayID );
#ifdef HAVE_STIME #ifdef HAVE_STIME
test.printf( "AND stime = 'epoch'" ); test.catf( "AND stime = 'epoch'" );
#endif #endif
return getCountWhere( MSGS_TABLE, test ); return getCountWhere( MSGS_TABLE, test );
@ -969,13 +969,13 @@ DBMgr::StoreMessage( DevIDRelay devID, const uint8_t* const buf,
StrWPF query; StrWPF query;
if ( m_useB64 ) { if ( m_useB64 ) {
gchar* b64 = g_base64_encode( buf, len ); gchar* b64 = g_base64_encode( buf, len );
query.printf( fmt, "msg64", devID, "", b64, len ); query.catf( fmt, "msg64", devID, "", b64, len );
g_free( b64 ); g_free( b64 );
} else { } else {
uint8_t* bytes = PQescapeByteaConn( getThreadConn(), buf, uint8_t* bytes = PQescapeByteaConn( getThreadConn(), buf,
len, &newLen ); len, &newLen );
assert( NULL != bytes ); assert( NULL != bytes );
query.printf( fmt, "msg", devID, "E", bytes, len ); query.catf( fmt, "msg", devID, "E", bytes, len );
PQfreemem( bytes ); PQfreemem( bytes );
} }
@ -1008,23 +1008,23 @@ DBMgr::StoreMessage( const char* const connName, int hid,
StrWPF query; StrWPF query;
if ( m_useB64 ) { if ( m_useB64 ) {
gchar* b64 = g_base64_encode( buf, len ); gchar* b64 = g_base64_encode( buf, len );
query.printf( fmt, "msg64", connName, hid, devID, hid, connName, query.catf( fmt, "msg64", connName, hid, devID, hid, connName,
"", b64, len ); "", b64, len );
query.printf( " WHERE NOT EXISTS (SELECT 1 FROM " MSGS_TABLE query.catf( " WHERE NOT EXISTS (SELECT 1 FROM " MSGS_TABLE
" WHERE connname='%s' AND hid=%d AND msg64='%s'" " WHERE connname='%s' AND hid=%d AND msg64='%s'"
#ifdef HAVE_STIME #ifdef HAVE_STIME
" AND stime='epoch'" " AND stime='epoch'"
#endif #endif
" );", connName, hid, b64 ); " );", connName, hid, b64 );
g_free( b64 ); g_free( b64 );
} else { } else {
uint8_t* bytes = PQescapeByteaConn( getThreadConn(), buf, uint8_t* bytes = PQescapeByteaConn( getThreadConn(), buf,
len, &newLen ); len, &newLen );
assert( NULL != bytes ); assert( NULL != bytes );
query.printf( fmt, "msg", connName, hid, devID, hid, connName, query.catf( fmt, "msg", connName, hid, devID, hid, connName,
"E", bytes, len ); "E", bytes, len );
PQfreemem( bytes ); PQfreemem( bytes );
} }
@ -1068,18 +1068,18 @@ DBMgr::storedMessagesImpl( string test, vector<DBMgr::MsgInfo>& msgs,
bool nullConnnameOK ) bool nullConnnameOK )
{ {
StrWPF query; StrWPF query;
query.printf( "SELECT id, msg64, msg, msglen, token, connname FROM " query.catf( "SELECT id, msg64, msg, msglen, token, connname FROM "
MSGS_TABLE " WHERE %s " MSGS_TABLE " WHERE %s "
#ifdef HAVE_STIME #ifdef HAVE_STIME
" AND stime = 'epoch' " " AND stime = 'epoch' "
#endif #endif
" AND (connname IN (SELECT connname FROM " GAMES_TABLE " AND (connname IN (SELECT connname FROM " GAMES_TABLE
" WHERE NOT " GAMES_TABLE ".dead)", test.c_str() ); " WHERE NOT " GAMES_TABLE ".dead)", test.c_str() );
if ( nullConnnameOK ) { if ( nullConnnameOK ) {
query.printf( " OR connname IS NULL "); query.catf( " OR connname IS NULL ");
} }
query.printf( ") ORDER BY id" ); query.catf( ") ORDER BY id" );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
@ -1108,7 +1108,7 @@ DBMgr::GetStoredMessages( DevIDRelay relayID, vector<MsgInfo>& msgs )
{ {
if ( !hasNoMessages( relayID ) ) { if ( !hasNoMessages( relayID ) ) {
StrWPF query; StrWPF query;
query.printf( "devid=%d", relayID ); query.catf( "devid=%d", relayID );
storedMessagesImpl( query, msgs, true ); storedMessagesImpl( query, msgs, true );
if ( 0 == msgs.size() ) { if ( 0 == msgs.size() ) {
@ -1123,7 +1123,7 @@ DBMgr::GetStoredMessages( const char* const connName, HostID hid,
{ {
if ( !hasNoMessages( connName, hid ) ) { if ( !hasNoMessages( connName, hid ) ) {
StrWPF query; StrWPF query;
query.printf( "hid = %d AND connname = '%s'", hid, connName ); query.catf( "hid = %d AND connname = '%s'", hid, connName );
storedMessagesImpl( query, msgs, false ); storedMessagesImpl( query, msgs, false );
if ( 0 == msgs.size() ) { if ( 0 == msgs.size() ) {
@ -1143,7 +1143,7 @@ DBMgr::RemoveStoredMessages( string& msgids )
#endif #endif
" WHERE id IN (%s)"; " WHERE id IN (%s)";
StrWPF query; StrWPF query;
query.printf( fmt, msgids.c_str() ); query.catf( fmt, msgids.c_str() );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
execSql( query ); execSql( query );
} }
@ -1156,7 +1156,7 @@ DBMgr::RemoveStoredMessages( const int* msgIDs, int nMsgIDs )
size_t len = 0; size_t len = 0;
int ii; int ii;
for ( ii = 0; ; ) { for ( ii = 0; ; ) {
ids.printf( "%d", msgIDs[ii] ); ids.catf( "%d", msgIDs[ii] );
assert( len < sizeof(ids) ); assert( len < sizeof(ids) );
if ( ++ii == nMsgIDs ) { if ( ++ii == nMsgIDs ) {
break; break;
@ -1175,11 +1175,11 @@ DBMgr::RemoveStoredMessages( vector<int>& idv )
StrWPF ids; StrWPF ids;
vector<int>::const_iterator iter = idv.begin(); vector<int>::const_iterator iter = idv.begin();
for ( ; ; ) { for ( ; ; ) {
ids.printf( "%d", *iter ); ids.catf( "%d", *iter );
if ( ++iter == idv.end() ) { if ( ++iter == idv.end() ) {
break; break;
} }
ids.printf( "," ); ids.catf( "," );
} }
RemoveStoredMessages( ids ); RemoveStoredMessages( ids );
} }
@ -1195,7 +1195,7 @@ int
DBMgr::getCountWhere( const char* table, string& test ) DBMgr::getCountWhere( const char* table, string& test )
{ {
StrWPF query; StrWPF query;
query.printf( "SELECT count(*) FROM %s WHERE %s", table, test.c_str() ); query.catf( "SELECT count(*) FROM %s WHERE %s", table, test.c_str() );
PGresult* result = PQexec( getThreadConn(), query.c_str() ); PGresult* result = PQexec( getThreadConn(), query.c_str() );
assert( 1 == PQntuples( result ) ); assert( 1 == PQntuples( result ) );
@ -1207,7 +1207,7 @@ DBMgr::getCountWhere( const char* table, string& test )
void void
DBMgr::formatKey( StrWPF& key, const char* const connName, HostID hid ) DBMgr::formatKey( StrWPF& key, const char* const connName, HostID hid )
{ {
key.printf( "%s:%d", connName, hid ); key.catf( "%s:%d", connName, hid );
} }
bool bool
@ -1338,8 +1338,8 @@ DBMgr::getThreadConn( void )
assert( 0 ); assert( 0 );
} }
StrWPF params; StrWPF params;
params.printf( "dbname = %s ", buf ); params.catf( "dbname = %s ", buf );
params.printf( "port = %d ", port ); params.catf( "port = %d ", port );
conn = PQconnectdb( params.c_str() ); conn = PQconnectdb( params.c_str() );
pthread_setspecific( m_conn_key, conn ); pthread_setspecific( m_conn_key, conn );

View file

@ -177,8 +177,8 @@ DevMgr::printDevices( StrWPF& str, const vector<DevIDRelay>& devids )
uint32_t age = *keysIter; uint32_t age = *keysIter;
DevIDRelay devid = agedDevs.find( age )->second; DevIDRelay devid = agedDevs.find( age )->second;
age = now - age; age = now - age;
str.printf( "%.3d: devid: % 10d; age: %.3d seconds\n", ++row, str.catf( "%.3d: devid: % 10d; age: %.3d seconds\n", ++row,
devid, age ); devid, age );
} }
} }

View file

@ -28,7 +28,7 @@
*/ */
void void
StrWPF::printf( const char* fmt, ... ) StrWPF::catf( const char* fmt, ... )
{ {
const int origsiz = size(); const int origsiz = size();
int addsiz = 100; int addsiz = 100;

View file

@ -24,7 +24,7 @@
class StrWPF : public std::string { class StrWPF : public std::string {
public: public:
void printf( const char* fmt, ... ); void catf( const char* fmt, ... );
}; };
#endif #endif

View file

@ -496,7 +496,7 @@ XWThreadPool::print_in_use( void )
for ( iter = m_sockets_in_use.begin(); for ( iter = m_sockets_in_use.begin();
iter != m_sockets_in_use.end(); ++iter ) { iter != m_sockets_in_use.end(); ++iter ) {
str.printf( "%d ", *iter ); str.catf( "%d ", *iter );
} }
if ( 0 < str.size() ) { if ( 0 < str.size() ) {
logf( XW_LOGINFO, "Sockets in use: %s", str.c_str() ); logf( XW_LOGINFO, "Sockets in use: %s", str.c_str() );

View file

@ -149,8 +149,8 @@ UDPAckTrack::printAcksImpl( StrWPF& out )
MutexLock ml( &m_mutex ); MutexLock ml( &m_mutex );
map<uint32_t, AckRecord>::const_iterator iter; map<uint32_t, AckRecord>::const_iterator iter;
for ( iter = m_pendings.begin(); m_pendings.end() != iter; ++iter ) { for ( iter = m_pendings.begin(); m_pendings.end() != iter; ++iter ) {
out.printf( "id: % 8d; stl: %04d\n", iter->first, out.catf( "id: % 8d; stl: %04d\n", iter->first,
(iter->second.m_createTime + limit) - now ); (iter->second.m_createTime + limit) - now );
} }
} }
@ -215,11 +215,11 @@ UDPAckTrack::threadProc()
StrWPF leaked; StrWPF leaked;
vector<uint32_t>::const_iterator iter = older.begin(); vector<uint32_t>::const_iterator iter = older.begin();
for ( ; ; ) { for ( ; ; ) {
leaked.printf( "%d", *iter ); leaked.catf( "%d", *iter );
if ( ++iter == older.end() ) { if ( ++iter == older.end() ) {
break; break;
} }
leaked.printf( ", " ); leaked.catf( ", " );
} }
logf( XW_LOGERROR, "%s: these packets leaked (were not ack'd " logf( XW_LOGERROR, "%s: these packets leaked (were not ack'd "
"within %d seconds): %s", __func__, "within %d seconds): %s", __func__,