void c_RestResponse::SendError(MgException* e) { MG_TRY() #ifdef _MG_ENT_2011 STRING shortError = mgException->GetExceptionMessage(); #else STRING shortError = mgException->GetMessage(); #endif STRING longError = e->GetDetails(); STRING statusMessage = e->GetClassName(); //TODO: Use a string resource for html error text format string sResponseHeader; char tempHeader[4096]; m_HttpData.SetStatusAndReason(559,MG_WCHAR_TO_CHAR(statusMessage)); sprintf(tempHeader, "%s%s", MapAgentStrings::TextHtml, MapAgentStrings::Utf8Text); m_HttpData.AddHeader(MapAgentStrings::ContentTypeKey,tempHeader); WriteContent("\r\n" "<html>\n<head>\n" "<title>%s</title>\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n" "</head>\n" "<body>\n<h2>%s</h2>\n%s\n</body>\n</html>\n", MG_WCHAR_TO_CHAR(statusMessage), MG_WCHAR_TO_CHAR(shortError), MG_WCHAR_TO_CHAR(longError)); MG_CATCH(L"IsapiResponseHandler.SendError") }
void Http::TRequestProtocol::Encode(TStreamBuffer& Buffer) { // set a default if method not specified // gr: this was set in the constructor, but now for decoding we want to initialise it blank if ( mMethod.empty() ) mMethod = "GET"; Soy::Assert( mMethod=="GET" || mMethod=="POST", "Invalid method for HTTP request" ); // write request header { std::string HttpVersion; if ( mHost.empty() ) HttpVersion = "HTTP/1.0"; else HttpVersion = "HTTP/1.1"; std::stringstream RequestHeader; RequestHeader << mMethod << " /" << mUrl << " " << HttpVersion << "\r\n"; Buffer.Push( RequestHeader.str() ); } //mHeaders["Accept"] = "text/html"; if ( !mHost.empty() ) mHeaders["Host"] = mHost; //mHeaders["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"; BakeHeaders(); WriteHeaders( Buffer ); WriteContent( Buffer ); }
// A thin wrapper around gcc // Its soul purpose is to parse gcc's output and to store the parsed output // in a sqlite database int main(int argc, char **argv) { // We require at least one argument if ( argc < 2 ) { return -1; } StringVec_t file_names; const char *pdb = getenv("CL_COMPILATION_DB"); std::string commandline; for ( int i=1; i<argc; ++i ) { // Wrap all arguments with spaces with double quotes std::string arg = argv[i]; std::string file_name; if ( is_source_file( arg, file_name ) ) { file_names.push_back( file_name ); } // re-escape double quotes if needed size_t pos = arg.find('"'); while ( pos != std::string::npos ) { arg.replace(pos, 1, "\\\""); // replace it with escapted slash pos = arg.find('"', pos + 2); } if ( arg.find(' ') != std::string::npos ) { std::string a = "\""; a += arg; a += '"'; arg.swap(a); } commandline += arg + " "; } if ( pdb ) { for(size_t i=0; i<file_names.size(); ++i) { #if __DEBUG printf("filename: %s\n", file_names.at(i).c_str()); #endif std::string logfile = pdb; logfile += ".txt"; WriteContent(logfile, file_names.at(i), commandline); } } #ifdef _WIN32 int exitCode = ::ExecuteProcessWIN(commandline); return exitCode; #else return execvp(argv[1], argv+1); #endif }
void CRunLog::WriteRunLog(const char *shm,...) { char buffer[MAX_LINE_SIZE]; va_list sp; AddHead(buffer); va_start(sp,shm); vsnprintf(buffer+strlen(buffer),MAX_LINE_SIZE - strlen(buffer),shm,sp); va_end(sp); strcat(buffer,"\n"); buffer[MAX_LINE_SIZE - 2] = '\n'; if (GetFileSize(this->LogFile) > this->FileSize) ResetFile(); if (NULL == fp) OpenFile(); WriteContent(buffer); }
void CaseContent::CompileToCaseFile(QString filePath) { ArchiveWriter caseArchiveWriter; if (!caseArchiveWriter.Init(projectFileDir.absolutePath() + "/" + filePath)) { return; } int spriteIndex = 0; for (QMap<QString, Location *>::iterator iter = LocationIdToLocationMap.begin(); iter != LocationIdToLocationMap.end(); iter++) { char filename[256]; sprintf(filename, "Images/Background%d.png", spriteIndex + 1); spriteIndex++; if (!caseArchiveWriter.SaveFile(iter.value()->GetBackgroundFilePath(), filename)) { return; } } XmlWriter caseFileWriter(NULL, NULL, true /* makeHumanReadable */, 2 /* formattingVersion */); caseFileWriter.StartElement("Case"); WriteAnimationManager(&caseFileWriter); WriteAudioManager(&caseFileWriter); WriteContent(&caseFileWriter); WriteDialogCharacterManager(&caseFileWriter); WriteDialogCutsceneManager(&caseFileWriter); WriteEvidenceManager(&caseFileWriter); WriteFieldCharacterManager(&caseFileWriter); WriteFieldCutsceneManager(&caseFileWriter); WriteFlagManager(&caseFileWriter); WritePartnerManager(&caseFileWriter); WriteSpriteManager(&caseFileWriter); WriteParentLocationListsBySpriteSheetId(&caseFileWriter); WriteParentLocationListsByVideoId(&caseFileWriter); caseFileWriter.EndElement(); caseArchiveWriter.SaveToFile(caseFileWriter.GetXmlString(), "case.xml"); caseArchiveWriter.Close(); }
bool GOrgueArchiveIndex::WriteIndex(const wxString& id, const std::vector<GOArchiveEntry>& entries) { wxString name = GenerateIndexFilename(); if (!m_File.Create(name, true) || !m_File.IsOpened()) { m_File.Close(); wxLogError(_("Failed to write to '%s'"), name.c_str()); return false; } if (!WriteContent(id, entries)) { m_File.Close(); wxLogError(_("Failed to write content to '%s'"), name.c_str()); return false; } m_File.Close(); return true; }
void Http::TResponseProtocol::Encode(TStreamBuffer& Buffer) { size_t ResultCode = Response_OK; std::string ResultString; // specific response if ( mResponseCode != 0 ) { ResultCode = mResponseCode; } if ( !mUrl.empty() ) { ResultString = mUrl; } if ( ResultString.empty() ) ResultString = GetDefaultResponseString( ResultCode ); // write request header { std::string HttpVersion; /* if ( mHost.empty() ) HttpVersion = "HTTP/1.0"; else */ HttpVersion = "HTTP/1.1"; std::stringstream RequestHeader; RequestHeader << HttpVersion << " " << ResultCode << " " << ResultString << "\r\n"; Buffer.Push( RequestHeader.str() ); } BakeHeaders(); WriteHeaders( Buffer ); WriteContent( Buffer ); }