void svStorageEnginePostgreSQL::GetHostKey( const string &dev, const string &org, svHostKey &key) { string sql(sql_query_hostkey); string value(dev); EscapeString(value); if (PrepareSQL(sql, "%d", value) == 0) throw svExStorageQuery("Invalid SQL, missing match token: device"); value = org; EscapeString(value); PrepareSQL(sql, "%o", value); ExecuteSQL(sql); if (PQresultStatus(pg_res) != PGRES_TUPLES_OK) { throw svExStorageQuery(string("PQexec: ") + PQresultErrorMessage(pg_res)); } if (PQntuples(pg_res) == 0) throw svExStorageRecordNotFound(name + ": Device not found: " + dev); key.SetAge(time(NULL)); key.SetKey(PQgetvalue(pg_res, 0, 0)); PQclear(pg_res); pg_res = NULL; }
void svStorageEngineMySQL::GetHostKey( const string &dev, const string &org, svHostKey &key) { string sql(sql_query_hostkey); string value(dev); EscapeString(value); if (PrepareSQL(sql, "%d", value) == 0) throw svExStorageQuery("Invalid SQL, missing match token: device"); value = org; EscapeString(value); PrepareSQL(sql, "%o", value); ExecuteSQL(sql); if (mysql_num_rows(mysql_res) == 0) throw svExStorageRecordNotFound(name + ": Device not found: " + dev); MYSQL_ROW row; if (!(row = mysql_fetch_row(mysql_res))) { throw svExStorageQuery(name + string(": mysql_fetch_row: ") + mysql_error(mysql_conn)); } key.SetAge(time(NULL)); key.SetKey(row[0]); mysql_free_result(mysql_res); mysql_res = NULL; }
void svStorageEngineMySQL::InsertPoolClient(const string &node, const string &pool_name, const string &dev, const string &org, svPoolClientState state) { if (sql_insert_pool_client.size() == 0) throw svExStorageQuery("No SQL query set: insert-pool-client"); string sql(sql_insert_pool_client); string value(dev); EscapeString(value); if (PrepareSQL(sql, "%d", value) == 0) throw svExStorageQuery("Invalid SQL, missing match token: device"); value = node; EscapeString(value); PrepareSQL(sql, "%n", value); value = pool_name; EscapeString(value); PrepareSQL(sql, "%p", value); value = org; EscapeString(value); PrepareSQL(sql, "%o", value); ostringstream os; map<svPoolClientState, string>::iterator i; i = pool_client_state.find(state); if (i == pool_client_state.end()) os << state; else os << i->second; PrepareSQL(sql, "%s", os.str()); ExecuteSQL(sql); }
void svStorageEngineMySQL::UpdatePoolClient(const string &node, const string &pool_name, const string &dev, const string &org, svPoolClientState state) { if (sql_update_pool_client.size() == 0) throw svExStorageQuery("No SQL query set: update-pool-client"); string sql(sql_update_pool_client); string value(dev); EscapeString(value); if (PrepareSQL(sql, "%d", value) == 0) throw svExStorageQuery("Invalid SQL, missing match token: device"); value = node; EscapeString(value); PrepareSQL(sql, "%n", value); value = pool_name; EscapeString(value); PrepareSQL(sql, "%p", value); value = org; EscapeString(value); PrepareSQL(sql, "%o", value); ostringstream os; map<svPoolClientState, string>::iterator i; i = pool_client_state.find(state); if (i == pool_client_state.end()) os << state; else os << i->second; PrepareSQL(sql, "%s", os.str()); ExecuteSQL(sql); my_ulonglong affected_rows = mysql_affected_rows(mysql_conn); if (affected_rows == 0) throw svExStorageRecordNotFound("Pool client not found"); }
void FOOTPRINT_LIST_IMPL::WriteCacheToFile( wxTextFile* aCacheFile ) { if( aCacheFile->Exists() ) { aCacheFile->Open(); aCacheFile->Clear(); } else { aCacheFile->Create(); } aCacheFile->AddLine( wxString::Format( "%lld", m_list_timestamp ) ); for( auto& fpinfo : m_list ) { aCacheFile->AddLine( fpinfo->GetLibNickname() ); aCacheFile->AddLine( fpinfo->GetName() ); aCacheFile->AddLine( EscapeString( fpinfo->GetDescription() ) ); aCacheFile->AddLine( EscapeString( fpinfo->GetKeywords() ) ); aCacheFile->AddLine( wxString::Format( "%d", fpinfo->GetOrderNum() ) ); aCacheFile->AddLine( wxString::Format( "%u", fpinfo->GetPadCount() ) ); aCacheFile->AddLine( wxString::Format( "%u", fpinfo->GetUniquePadCount() ) ); } aCacheFile->Write(); aCacheFile->Close(); }
wxString FileUtils::GetOSXTerminalCommand(const wxString& command, const wxString& workingDirectory) { wxFileName script(clStandardPaths::Get().GetBinFolder(), "osx-terminal.sh"); wxString cmd; cmd << EscapeString(script.GetFullPath()) << " \""; if(!workingDirectory.IsEmpty()) { cmd << "cd " << EscapeString(workingDirectory) << " && "; } cmd << EscapeString(command) << "\""; clDEBUG() << "GetOSXTerminalCommand returned:" << cmd << clEndl; return cmd; }
std::string BaseRowsetReader::iterator::GetAsString( size_t index ) const { const PyRep::PyType t = GetType( index ); switch( t ) { case PyRep::PyTypeNone: return "NULL"; case PyRep::PyTypeBool: return itoa( GetBool( index ) ? 1 : 0 ); case PyRep::PyTypeInt: return itoa( GetInt( index ) ); case PyRep::PyTypeLong: return itoa( GetLong( index ) ); case PyRep::PyTypeFloat: { char buf[64]; snprintf( buf, 64, "%f", GetFloat( index ) ); return buf; } case PyRep::PyTypeString: { std::string str = GetString( index ); EscapeString( str, "'", "\\'" ); str.insert( str.begin(), '\'' ); str.insert( str.end(), '\'' ); return str; } case PyRep::PyTypeWString: { std::string str = GetWString( index ); EscapeString( str, "'", "\\'" ); str.insert( str.begin(), '\'' ); str.insert( str.end(), '\'' ); return str; } default: { char buf[64]; snprintf( buf, 64, "'UNKNOWN TYPE %u'", t ); return buf; } } }
void QueryServ::PlayerLogEvent(int Event_Type, int Character_ID, std::string Event_Desc) { std::string query = StringFormat( "INSERT INTO `qs_player_events` (event, char_id, event_desc, time) VALUES (%i, %i, '%s', UNIX_TIMESTAMP(now()))", Event_Type, Character_ID, EscapeString(Event_Desc).c_str()); SendQuery(query); }
void JsonObjectValue::Print(FILE * stream, int indent, bool indentFirst) { if (indentFirst) { PrintIndent(stream, indent); } ::fprintf(stream, "{\n"); ValuesList::iterator last = values_.end(); --last; for (ValuesList::iterator itr = values_.begin(); itr != values_.end(); ++itr) { PrintIndent(stream, indent + 1); ::fprintf(stream, "\"%s\" : ", EscapeString(itr->first).c_str()); if (itr->second == 0) { PrintNull(stream, 0); } else { itr->second->Print(stream, indent + 1, false); } if (itr != last) { ::fprintf(stream, ","); } ::fprintf(stream, "\n"); } PrintIndent(stream, indent); ::fprintf(stream, "}"); }
void JsonObjectValue::PrintPlain(FILE * stream) { if (Empty()) { ::fprintf(stream, "{}"); return; } ::fprintf(stream, "{ "); ValuesList::iterator last = values_.end(); --last; for (ValuesList::iterator itr = values_.begin(); itr != values_.end(); ++itr) { ::fprintf(stream, "\"%s\" : ", EscapeString(itr->first).c_str()); if (itr->second == 0) { PrintNull(stream, 0); } else { itr->second->PrintPlain(stream); } if (itr != last) { ::fprintf(stream, ", "); } } ::fprintf(stream, " }"); }
void Raid::SaveRaidMOTD() { std::string query = StringFormat("UPDATE raid_details SET motd = '%s' WHERE raidid = %lu", EscapeString(motd).c_str(), (unsigned long)GetID()); auto results = database.QueryDatabase(query); }
/** * Interface to other classes for submitting a result of one test * * @param TestType * Constant pointer to a char array containing the test type to be run (i.e. "wine") * * @param TestInfo * Pointer to a CTestInfo object containing information about the test */ void CWebService::Submit(const char* TestType, CTestInfo* TestInfo) { auto_array_ptr<char> Response; auto_array_ptr<char> SuiteID; string Data; stringstream ss; if(!m_TestID) GetTestID(TestType); SuiteID.reset(GetSuiteID(TestType, TestInfo)); Data = "action=submit"; Data += Configuration.GetAuthenticationRequestString(); Data += "&testtype="; Data += TestType; Data += "&testid="; Data += m_TestID; Data += "&suiteid="; Data += SuiteID; Data += "&log="; Data += EscapeString(TestInfo->Log); Response.reset(DoRequest(Data)); if (strcmp(Response, "OK")) { ss << "When submitting the result, the server responded:" << endl << Response << endl; SSEXCEPTION; } }
void FormatResNode(CUniString& buf, CResNode* pNode, int iIndent, bool bIncludeSelf) { if (bIncludeSelf) { buf.Append(TabString(iIndent)); buf.Append(EscapeString(pNode->GetName(), false)); CUniString strLink=pNode->GetLink(); if (!strLink.IsEmpty()) { buf.Append(L"->"); buf.Append(EscapeString(strLink, false, true)); buf.Append(L";\r\n"); return; } buf.Append(L"\r\n"); buf.Append(TabString(iIndent)); buf.Append(L"{\r\n"); iIndent++; // Write values for (int i=0; i<pNode->GetValueCount(); i++) { buf.Append(TabString(iIndent)); buf.Append(EscapeString(pNode->GetValueName(i), false)); buf.Append(L"="); buf.Append(EscapeString(pNode->GetValue(i), true)); buf.Append(L";\r\n"); } } // Write sub sections for (int i=0; i<pNode->GetNodeCount(); i++) { FormatResNode(buf, pNode->GetNode(i), iIndent, true); } if (bIncludeSelf) { iIndent--; buf.Append(TabString(iIndent)); buf.Append(L"}\r\n"); } }
void svStorageEngineMySQL::PurgePoolClients( const string &node, const string &org) { if (sql_purge_pool_clients.size() == 0) throw svExStorageQuery("No SQL query set: purge-pool-clients"); string sql(sql_purge_pool_clients); string value(node); EscapeString(value); if (PrepareSQL(sql, "%n", value) == 0) throw svExStorageQuery("Invalid SQL, missing match token: node"); value = org; EscapeString(value); PrepareSQL(sql, "%o", value); ExecuteSQL(sql); }
void SerializedConsoleOutput::writeToString(std::string *str) const { std::stringstream ss; string temp; temp = _output; EscapeString(temp); ss << temp << "\n"; temp = _error; EscapeString(temp); ss << temp << "\n"; temp = _prompt; EscapeString(temp); ss << temp << "\n"; temp = _input; EscapeString(temp); ss << temp << "\n"; *str = ss.str(); }
/** * Deletes data bucket by key * @param bucket_key * @return */ bool DataBucket::DeleteData(std::string bucket_key) { std::string query = StringFormat( "DELETE FROM `data_buckets` WHERE `key` = '%s'", EscapeString(bucket_key).c_str() ); auto results = database.QueryDatabase(query); return results.Success(); }
std::string ParsedInternalKey::DebugString() const { char buf[50]; snprintf(buf, sizeof(buf), "' @ %llu : %d", (unsigned long long) sequence, int(type)); std::string result = "'"; result += EscapeString(user_key.ToString()); result += buf; return result; }
void DatabaseWorkerPool<T>::EscapeString(std::string& str) { if (str.empty()) return; char* buf = new char[str.size() * 2 + 1]; EscapeString(buf, str.c_str(), uint32(str.size())); str = buf; delete[] buf; }
static void DumpInternalIter(Iterator* iter) { for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { ParsedInternalKey k; if (!ParseInternalKey(iter->key(), &k)) { fprintf(stderr, "Corrupt '%s'\n", EscapeString(iter->key()).c_str()); } else { fprintf(stderr, "@ '%s'\n", k.DebugString().c_str()); } } }
std::string InternalKey::DebugString() const { std::string result; ParsedInternalKey parsed; if (ParseInternalKey(rep_, &parsed)) { result = parsed.DebugString(); } else { result = "(bad)"; result.append(EscapeString(rep_)); } return result; }
void Logger::log(const std::string &msg, const StackTrace *stackTrace, bool escape /* = true */, bool escapeMore /* = false */) { ASSERT(!escapeMore || escape); ThreadData *threadData = s_threadData.get(); if (++threadData->message > MaxMessagesPerRequest && MaxMessagesPerRequest >= 0) { return; } boost::shared_ptr<StackTrace> deleter; if (stackTrace == NULL) { deleter = boost::shared_ptr<StackTrace>(new StackTrace()); stackTrace = deleter.get(); } if (UseLogAggregator) { LogAggregator::TheLogAggregator.log(*stackTrace, msg); } if (UseLogFile) { FILE *f = Output ? Output : stdout; string header, sheader; if (LogHeader) { header = GetHeader(); if (LogNativeStackTrace) { sheader = header + "[" + stackTrace->hexEncode(5) + "] "; } else { sheader = header; } } const char *escaped = escape ? EscapeString(msg) : msg.c_str(); const char *ending = escapeMore ? "\\n" : "\n"; if (f == stdout && Util::s_stderr_color) { fprintf(f, "%s%s%s%s%s", Util::s_stderr_color, sheader.c_str(), msg.c_str(), ending, ANSI_COLOR_END); } else { fprintf(f, "%s%s%s", sheader.c_str(), escaped, ending); } FILE *tf = threadData->log; if (tf) { fprintf(tf, "%s%s%s", header.c_str(), escaped, ending); fflush(tf); } if (threadData->hook) { threadData->hook(header.c_str(), escaped, ending, threadData->hookData); } if (escape) { free((void*)escaped); } fflush(f); } }
void svStorageEnginePostgreSQL::UpdatePoolClient(const string &node, const string &pool_name, const string &dev, const string &org, svPoolClientState state) { if (sql_update_pool_client.size() == 0) throw svExStorageQuery("No SQL query set: update-pool-client"); string sql(sql_update_pool_client); string value(dev); EscapeString(value); if (PrepareSQL(sql, "%d", value) == 0) throw svExStorageQuery("Invalid SQL, missing match token: device"); value = node; EscapeString(value); PrepareSQL(sql, "%n", value); value = pool_name; EscapeString(value); PrepareSQL(sql, "%p", value); value = org; EscapeString(value); PrepareSQL(sql, "%o", value); ostringstream os; map<svPoolClientState, string>::iterator i; i = pool_client_state.find(state); if (i == pool_client_state.end()) os << state; else os << i->second; PrepareSQL(sql, "%s", os.str()); ExecuteSQL(sql); if (PQresultStatus(pg_res) != PGRES_COMMAND_OK) { throw svExStorageQuery(string("PQexec: ") + PQresultErrorMessage(pg_res)); } uint32_t affected_rows = (uint32_t)atoi(PQcmdTuples(pg_res)); if (affected_rows == 0) throw svExStorageRecordNotFound("Pool client not found"); }
void XmlWriter::WriteNamespace(const Namespace& rNamespace) { if (rNamespace.GetPrefix().empty()) { m_rStream << " xmlns"; } else { m_rStream << " xmlns:" << rNamespace.GetPrefix(); } m_rStream << "=\"" << EscapeString(rNamespace.GetUri()) << "\""; }
void svStorageEnginePostgreSQL::PurgePoolClients( const string &node, const string &org) { if (sql_purge_pool_clients.size() == 0) throw svExStorageQuery("No SQL query set: purge-pool-clients"); string sql(sql_purge_pool_clients); string value(node); EscapeString(value); if (PrepareSQL(sql, "%n", value) == 0) throw svExStorageQuery("Invalid SQL, missing match token: node"); value = org; EscapeString(value); PrepareSQL(sql, "%o", value); ExecuteSQL(sql); if (PQresultStatus(pg_res) != PGRES_COMMAND_OK) { throw svExStorageQuery(string("PQexec: ") + PQresultErrorMessage(pg_res)); } }
void cProtocolRecognizer::SendDisconnect(const AString & a_Reason) { if (m_Protocol != nullptr) { m_Protocol->SendDisconnect(a_Reason); } else { AString Message = Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str()); cPacketizer Pkt(*this, 0x00); // Disconnect packet (in login state) Pkt.WriteString(Message); } }
/** * Persists data via bucket_name as key * @param bucket_key * @param bucket_value * @param expires_time */ void DataBucket::SetData(std::string bucket_key, std::string bucket_value, std::string expires_time) { uint64 bucket_id = DataBucket::DoesBucketExist(bucket_key); std::string query; long long expires_time_unix = 0; if (!expires_time.empty()) { if (isalpha(expires_time[0]) || isalpha(expires_time[expires_time.length() - 1])) { expires_time_unix = (long long) std::time(nullptr) + DataBucket::ParseStringTimeToInt(expires_time); } else { expires_time_unix = (long long) std::time(nullptr) + atoi(expires_time.c_str()); } } if (bucket_id > 0) { std::string update_expired_time; if (expires_time_unix > 0) { update_expired_time = StringFormat(", `expires` = %lld ", expires_time_unix); } query = StringFormat( "UPDATE `data_buckets` SET `value` = '%s' %s WHERE `id` = %i", EscapeString(bucket_value).c_str(), EscapeString(update_expired_time).c_str(), bucket_id ); } else { query = StringFormat( "INSERT INTO `data_buckets` (`key`, `value`, `expires`) VALUES ('%s', '%s', '%lld')", EscapeString(bucket_key).c_str(), EscapeString(bucket_value).c_str(), expires_time_unix ); } database.QueryDatabase(query); }
int FontMatchInfoObject:: addToString(const char *&str, int &strLen, int &strMaxLen, struct fmi_attr_store *ele) { const char *value; char *newValue = NULL; char strValue[64]; // XXX There must be a better way to do this. int ret = 0; addToString(str, strLen, strMaxLen, FMI_FONTPART_SEPERATOR); if (count() > MAX_STANDARD_ATTRIBUTES) { // Add the attribute also addToString(str, strLen, strMaxLen, ele->attr); addToString(str, strLen, strMaxLen, ":"); } if (ele->valueType == FMI_TYPE_JINT) { strValue[0] = '\0'; if (ele->u.intValue > 0) { sprintf(strValue, "%d", ele->u.intValue); } value = strValue; } else { // Escape {:-*} in value. These have special meaning to us. value = ele->u.stringValue; if (value && *value) { newValue = EscapeString(value, needsEscape); if (!newValue) { // ERROR: No memory return (-1); } value = newValue; } } ret = addToString(str, strLen, strMaxLen, value); if (newValue) { delete[] newValue; } return (ret); }
/** * Checks for bucket existence by bucket_name key * @param bucket_key * @return */ uint64 DataBucket::DoesBucketExist(std::string bucket_key) { std::string query = StringFormat( "SELECT `id` from `data_buckets` WHERE `key` = '%s' AND (`expires` > %lld OR `expires` = 0) LIMIT 1", EscapeString(bucket_key).c_str(), (long long) std::time(nullptr) ); auto results = database.QueryDatabase(query); if (!results.Success()) { return 0; } auto row = results.begin(); if (results.RowCount() != 1) return 0; return std::stoull(row[0]); }
// Specialization of Print above for pointer types. template<> void Print<const void *>(const void *val, Type type, int indent, StructDef *union_sd, const IDLOptions &opts, std::string *_text) { switch (type.base_type) { case BASE_TYPE_UNION: // If this assert hits, you have an corrupt buffer, a union type field // was not present or was out of range. assert(union_sd); GenStruct(*union_sd, reinterpret_cast<const Table *>(val), indent, opts, _text); break; case BASE_TYPE_STRUCT: GenStruct(*type.struct_def, reinterpret_cast<const Table *>(val), indent, opts, _text); break; case BASE_TYPE_STRING: { EscapeString(*reinterpret_cast<const String *>(val), _text); break; } case BASE_TYPE_VECTOR: type = type.VectorType(); // Call PrintVector above specifically for each element type: switch (type.base_type) { #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, \ PTYPE) \ case BASE_TYPE_ ## ENUM: \ PrintVector<CTYPE>( \ *reinterpret_cast<const Vector<CTYPE> *>(val), \ type, indent, opts, _text); break; FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) #undef FLATBUFFERS_TD } break; default: assert(0); } }
static BOOL CALLBACK FBALocaliseEnumResourceNamesString(HMODULE /* hModule */, LPCTSTR /* lpszType */, LPTSTR lpszName, LONG_PTR lParam) { wchar_t* pwsz = (wchar_t*)LoadResource(hAppInst, FindResource(hAppInst, lpszName, RT_STRING)); if (LockResource(pwsz)) { wchar_t wszBuffer[5120]; // Locate the string in the bundle for (int i = 0; i < 16; i++) { if (*pwsz) { EscapeString(wszBuffer, pwsz + 1, 5120); _ftprintf((FILE*)lParam, _T(" //-- \"%ls\"\n"), wszBuffer); _ftprintf((FILE*)lParam, _T("string %5i \"\"\n\n"), (((int)lpszName) - 1) * 16 + i); } pwsz += *pwsz + 1; } } return TRUE; }