PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX * amx) { Redirect(amx, "SetTimer", (ucell)n_SetTimer, 0); Redirect(amx, "KillTimer", (ucell)n_KillTimer, 0); Redirect(amx, "SetTimerEx", (ucell)n_SetTimerEx, 0); //Redirect(amx, "print", (ucell)n_print, 0); //Redirect(amx, "printf", (ucell)n_printf, 0); for (int i = 0; i != 17; ++i) { if (gAMXFiles[i] == 0) { gAMXFiles[i] = amx; int idx; if (amx_FindPublic(amx, "OnServerMessage", &idx)) { //printf("NO CALLBACK\n"); gAMXPtr[i] = -1; } else { //printf("GOT CALLBACK %d\n", idx); gAMXPtr[i] = idx; } break; } } return amx_Register(amx, sscanfNatives, -1); }
PYBIND11_MODULE(modellib, m) { using Redirect = py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>; py::class_<Model>(m, "ModelBuilder") .def(py::init<>(), Redirect()) .def("imp", &Model::imp, Redirect()) .def("exp", &Model::exp, Redirect()) .def("supported_extensions", &Model::getExtensions) .def("error_string", &Model::getErrorString); }
bool Win32Console::Create() { if (!m_IsOpen) { if (AllocConsole()) { if (Redirect(GetStdHandle(STD_OUTPUT_HANDLE), stdout, "w") && Redirect(GetStdHandle(STD_INPUT_HANDLE), stdin, "r") && Redirect(GetStdHandle(STD_ERROR_HANDLE), stderr, "w")) { m_IsOpen = TRUE; SetConsoleCtrlHandler(SignalHandler, TRUE); } } } return(m_IsOpen); }
/******************************************************************************************** > virtual BOOL CamLaunchProcess::Execute(const wxString& cmd) Author: Phil_Martin (Xara Group Ltd) <*****@*****.**> Created: 19/May/2006 Inputs: cmd - The command string including parameters Outputs: - Returns: TRUE if the command was launched successfully FALSE otherwise Purpose: Execute a command which should launch a long-running process ********************************************************************************************/ BOOL CamLaunchProcess::Execute(const wxString& cmd) { m_ReturnCode = 0; // Assume success until we find otherwise // Make sure redirection happens Redirect(); TRACEUSER("Phil", _T("Executing %s\n"), (LPCTSTR) cmd); m_pid = wxExecute(cmd, wxEXEC_ASYNC, this); if (m_pid==0) { // Couldn't even create a process for the command! m_bDead = true; return FALSE; } // We're now running m_bDead = false; m_bConnected = true; // Give the command 100 milliseconds to return an error condition or die... // After that we will either use the return code it passed back to OnTerminate // or assume it is running successfully... MonotonicTime graceperiod; while (!m_bDead && m_ReturnCode==0 && !graceperiod.Elapsed(100)) { ProcessStdErr(); // Process any output on stderr wxMilliSleep(1); wxYield(); } TRACEUSER("Phil", _T("Exiting with %d\n"), m_ReturnCode); return (m_ReturnCode==0); }
CFile::CFile(CBaseFile* pFile, bool bOwned) { m_pBaseFile = NULL; m_bOwned = true; SetStatus(FOCP_FILE_NORMAL); Redirect(pFile, bOwned); }
NS_IMETHODIMP nsBaseChannel::Open(nsIInputStream **result) { NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(!mPump, NS_ERROR_IN_PROGRESS); NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_IN_PROGRESS); nsCOMPtr<nsIChannel> chan; nsresult rv = OpenContentStream(false, result, getter_AddRefs(chan)); NS_ASSERTION(!chan || !*result, "Got both a channel and a stream?"); if (NS_SUCCEEDED(rv) && chan) { rv = Redirect(chan, nsIChannelEventSink::REDIRECT_INTERNAL, false); if (NS_FAILED(rv)) return rv; rv = chan->Open(result); } else if (rv == NS_ERROR_NOT_IMPLEMENTED) return NS_ImplementChannelOpen(this, result); if (NS_SUCCEEDED(rv)) { mWasOpened = true; ClassifyURI(); } return rv; }
void R3DSurfaceGenProcess::runSingleCommand() { if(!cmds_.IsEmpty()) { Redirect(); // Redirect I/O, hide console window wxString cmdLine = cmds_[0]; cmds_.RemoveAt(0); wxString progressText = progressTexts_[0]; progressTexts_.RemoveAt(0); pMainFrame_->sendUpdateProgressBarEvent(-1.0f, progressText); // Cleanup if(GetInputStream() != NULL) delete GetInputStream(); if(GetErrorStream() != NULL) delete GetErrorStream(); if(GetOutputStream() != NULL) delete GetOutputStream(); SetPipeStreams(NULL, NULL, NULL); #if wxCHECK_VERSION(2, 9, 0) processId_ = wxExecute(cmdLine, wxEXEC_ASYNC, this, &env_); #else processId_ = wxExecute(cmdLine, wxEXEC_ASYNC, this); #endif } }
GettextProcess(GettextProcessData *data, wxEvtHandler *parent) : wxProcess(parent), m_data(data) { m_data->Running = true; m_data->Stderr.Empty(); m_data->Stdout.Empty(); Redirect(); }
piped_process::piped_process( progress_dialog *parent, process_data_type *process_data ) : m_process_data( process_data ) { m_parent = parent; m_process_data->is_running = TRUE; // Turn on redirection for the process, so that it can be caught by the GetInputStream() // and GetErrorStream() functions in piped_process::has_input(). Redirect(); }
bool CWebSock::ForceLogin() { if (GetSession()->IsLoggedIn()) { return true; } GetSession()->AddError("You must login to view that page"); Redirect("/"); return false; }
CscopeProcess::CscopeProcess(CscopePlugin* parent): wxProcess(parent) { //ctor wxASSERT(parent); m_parent = parent; //turn on redirect Redirect(); }
AxProcess::AxProcess( wxString cmd, wxString args, AxProgressDlg *dlg ) //: wxProcess( dlg ) { Redirect(); m_pid = 0; m_status = 0; m_cmd = AxApp::GetAppPath() + "/" + cmd + " " + args; m_log = NULL; m_logStream = NULL; }
long PipedProcess::Start(bool hide) { Redirect(); long flags = wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER ; if(!hide){ flags |= wxEXEC_NOHIDE; } m_pid = wxExecute(m_cmd, flags, this); return m_pid; }
// class constructor PipedProcess::PipedProcess(void** pvThis, wxEvtHandler* parent, int id, bool pipe, const wxString& dir) : wxProcess(parent, id), m_Parent(parent), m_Id(id), m_Pid(0), m_pvThis(pvThis) { wxSetWorkingDirectory(UnixFilename(dir)); if (pipe) Redirect(); }
//This function prepares the content of stats context , ( stats.content ) void * serve_random_videopage(struct AmmServer_DynamicRequest * rqst) { unsigned int videoID=rand()%myTube->numberOfLoadedVideos; snprintf(rqst->content,rqst->MAXcontentSize,"<!DOCTYPE html>\n\ <html>\n\ <head>\n\ <script type=\"text/javascript\">\n\ <!--\n\ function Redirect() {\n\ window.location=\"watch?v=%u\";\n\ }\n\ //-->\n\ </script><meta http-equiv=\"refresh\" content=\"0;URL='watch?v=%u'\"/></head><body onload=\"Redirect();\"> </body></html> ",videoID,videoID);
static int main_console (int argc, char *argv[]) { if (condpy == NULL) { Init (argc, argv); Redirect (); } ProcessInput (); /*ams while (XPending (condpy)) ProcessEvent(); ams*/ if (XPending (condpy)) ProcessEvent(); return 1; }
// class constructor PipedProcess::PipedProcess(PipedProcess** pvThis, wxEvtHandler* parent, int id, bool pipe, const wxString& dir) : wxProcess(parent, id), m_Parent(parent), m_Id(id), m_Pid(0), m_pvThis(pvThis) { const wxString &unixDir = UnixFilename(dir); if (!unixDir.empty()) wxSetWorkingDirectory(unixDir); if (pipe) Redirect(); }
int32 CFile::Open(const CFileName& oFileName, const char* sOption) { CFileInterface* pInterface = (CFileInterface*)CFileInterface::GetInterfaceManager()->QueryInterface(oFileName.oProtocol.GetStr()); if(pInterface == NULL) return FOCP_FILE_PROTOCOL_ERROR; CBaseFile* pFile = pInterface->CreateFile(); int32 nRet = pFile->Open(oFileName, sOption); if(nRet) pInterface->DestroyFile(pFile); else Redirect(pFile); return nRet; }
void CPyProcess::Execute(const wxChar* cmd) { if(redirect) { Redirect(); } // make process group leader so Cancel kan terminate process including children m_pid = wxExecute(cmd, wxEXEC_ASYNC|wxEXEC_MAKE_GROUP_LEADER, this); if (!m_pid) { wxLogMessage(_T("could not execute '%s'"),cmd); } else { wxLogMessage(_T("starting '%s' (%d)"),cmd,m_pid); } if (redirect) { m_timer.Start(100); //msec } }
void nsBaseChannel::HandleAsyncRedirect(nsIChannel* newChannel) { NS_ASSERTION(!mPump, "Shouldn't have gotten here"); nsresult rv = mStatus; if (NS_SUCCEEDED(mStatus)) { rv = Redirect(newChannel, nsIChannelEventSink::REDIRECT_TEMPORARY, true); if (NS_SUCCEEDED(rv)) { // OnRedirectVerifyCallback will be called asynchronously return; } } ContinueHandleAsyncRedirect(rv); }
sysProcess::sysProcess(wxEvtHandler *evh) : wxProcess(evh) { pid = 0; Redirect(); }
INT32 CamProcess::Execute(const wxString& cmd) { // We're now running m_bDead = false; // Make sure redirection happens Redirect(); long pid = wxExecute(cmd, wxEXEC_ASYNC, this); if (pid == 0) { // Report problem m_bDead = true; return 123; } BYTE ReadBuffer[4096]; size_t ReadBytes = 0; BYTE* ReadPtr = NULL; bool bMoreInput = true; size_t InFileLeft = 0; if (m_pInFile) { InFileLeft = m_pInFile->Size(); // TRACEUSER("Gerry", _T("InFileSize = %d"), InFileLeft); } // Loop until m_bDead is true while (!m_bDead) { // Call the virtual function to process any output on stderr ProcessStdErr(); wxYield(); // If we have an output file if (m_pOutFile) { // If there is output from the process if (!m_bDead && IsInputAvailable()) { // Copy the data to the file size_t NumRead = 4096; BYTE Buffer[4096]; // Read a buffer full GetInputStream()->Read(Buffer, 4096); NumRead = GetInputStream()->LastRead(); // Write the buffer to the file if (NumRead > 0) { // TRACEUSER("Gerry", _T("Writing %d bytes of stdout"), NumRead); m_pOutFile->write(Buffer, NumRead); } } } else { // Call the virtual function to process the output if (!m_bDead) ProcessStdOut(); } wxYield(); // If we have an input file if (m_pInFile) { // Copy some data to the process // This was a while loop if (!m_bDead && bMoreInput) { // If there is nothing in the buffer if (ReadBytes == 0) { ReadBytes = 4096; if (ReadBytes > InFileLeft) ReadBytes = InFileLeft; if (ReadBytes > 0) { // Read a buffer full // TRACEUSER("Gerry", _T("Reading %d"), ReadBytes); m_pInFile->read(ReadBuffer, ReadBytes); InFileLeft -= ReadBytes; ReadPtr = ReadBuffer; } } // If there is something in the buffer if (ReadBytes > 0 && GetOutputStream()->IsOk()) { // TRACEUSER("Gerry", _T("Buffer contains %d"), ReadBytes); // Try to write it to the process GetOutputStream()->Write(ReadPtr, ReadBytes); size_t Done = GetOutputStream()->LastWrite(); // TRACEUSER("Gerry", _T("Written %d"), Done); // If we couldn't write it all if (Done < ReadBytes) { // Update the buffer pointer ReadPtr += Done; } // This is correct for all, part or none written ReadBytes -= Done; } else { // Indicate there is no more stdin // TRACEUSER("Gerry", _T("Buffer is empty - closing")); CloseOutput(); bMoreInput = false; } } } else { // Call the virtual function to process the input if (!m_bDead) ProcessStdIn(); } wxYield(); } // TRACEUSER("Gerry", _T("Exiting with %d"), m_ReturnCode); return m_ReturnCode; }
void QHttpHandler::addRedirect(const QRegExp &pattern, const QString &path) { d->redirects.append(Redirect(pattern, path)); }
void ImageServerConnection::ProcessHeaders() { std::istream stream(&_buffer); std::string request; // every request line ends with \r\n std::getline(stream, request, '\r'); if (!starts_with(request, "GET /")) { NotFound(); return; } request = request.substr(5); bool found = false; for (int i = 0; i < ImageServer::CategoryCount; i++) { if (starts_with(request, ImageServer::Categories[i])) { found = true; _category = ImageServer::Categories[i]; request = request.substr(strlen(ImageServer::Categories[i])); break; } } if (!found) { NotFound(); return; } if (!starts_with(request, "/")) { NotFound(); return; } request = request.substr(1); int del = request.find_first_of('_'); if (del == std::string::npos) { NotFound(); return; } // might have some extra data but atoi shouldn't care std::string idStr = request.substr(0, del); std::string sizeStr = request.substr(del + 1); _id = atoi(idStr.c_str()); _size = atoi(sizeStr.c_str()); _imageData = ImageServer::get().GetImage(_category, _id, _size); if (!_imageData) { Redirect(); return; } // first we have to send the responseOK, then our actual result asio::async_write(_socket, _responseOK, asio::transfer_all(), std::tr1::bind(&ImageServerConnection::SendImage, shared_from_this())); }
int main(int argc, char *argv[]){ int fd[4][2]; /* pipes array */ char *child[] = { "./P1", "./P2", "./P3" }; /* child binaries */ pid_t pid[3]; /* children pids*/ char input[EXPR_MAX_LEN * 2], expr[EXPR_MAX_LEN], output[EXPR_MAX_LEN]; int i, j, code; /* Initialize pipes */ for(i = 0; i < 4; i++) { code = pipe(fd[i]); if( code < 0 ) { perror("pipe"); exit(EXIT_FAILURE); } } /****************************Spawn child processes****************************/ for(i = 0; i < 3; i++) { /* Fork the proccess */ pid[i] = fork(); if( pid[i] == 0 ) { /* Child code */ /*rPipe: Read Pipe, wPipe: Write pipe*/ int rPipe = i, wPipe = i+1; /* Close the unsused pipes */ for(j = 0; j < 4; j++) { if( j != rPipe ) Close( fd[j][0] ); if( j != wPipe ) Close( fd[j][1] ); } /* Redirect stdin & stdout */ Redirect( fd[rPipe][0], 0); Redirect( fd[wPipe][1], 1); /* Execute the child code */ execlp( child[i] , child[i], NULL); /* If we get here we got an eror */ perror("execlp"); exit(EXIT_FAILURE); } else if ( pid[i] < 0 ) { /* Kill the previous children */ for(j = 0; j < i; j++) { kill(pid[j], SIGKILL); } perror("Fork failed"); exit(EXIT_FAILURE); } } /* Close the unused pipes in main */ for(j = 0; j < 4; j++) { if( j != 3 ) Close(fd[j][0]); if( j != 0 ) Close(fd[j][1]); } /* Initializing pollfd for poll-ing */ struct pollfd fdinfo[2]; fdinfo[0].fd = fd[3][0]; fdinfo[0].events = POLLIN; fdinfo[1].fd = fd[0][1]; fdinfo[1].events = POLLOUT; /******************************************************************** * ***** ****** MAIN LOOP ******************************************* *******************************************************************/ while ( 1 ) { printf( "Enter an expression up to %d characters long: ", EXPR_MAX_LEN - 2); while ( GetExpresssion(expr, EXPR_MAX_LEN) == 1 ){ printf( "Warning: Maximum expression length is %d!\n", EXPR_MAX_LEN ); printf("Please re-try: "); } /* Add spaces when needed */ if( expr[0] != ESCAPE_CHR ) AddSpaces(expr, input); else strcpy(input, expr); /* Write to pipe */ WaitForPipe( &fdinfo[1] ); Write(fdinfo[1].fd, input, strlen(input)); /* Read from pipe */ WaitForPipe( &fdinfo[0] ); Read(fdinfo[0].fd, output); if (expr[0] != ESCAPE_CHR ) { printf("Result: %s\n", output); } else break; } /* Clean up */ int childStatus; for(i = 0 ; i < 3; i++){ waitpid(pid[i], &childStatus, 0); } /* Close the pipes */ Close(fdinfo[0].fd); Close(fdinfo[1].fd); return 0; }
MonitoredProcess() { Redirect(); m_crashed=false; m_exitCode=0; }
CWebSock::EPageReqResult CWebSock::OnPageRequestInternal(const CString& sURI, CString& sPageRet) { if (CZNC::Get().GetProtectWebSessions() && GetSession()->GetIP() != GetRemoteIP()) { DEBUG("Expected IP: " << GetSession()->GetIP()); DEBUG("Remote IP: " << GetRemoteIP()); PrintErrorPage(403, "Access denied", "This session does not belong to your IP."); return PAGE_DONE; } // Check that they really POSTed from one our forms by checking if they // know the "secret" CSRF check value. Don't do this for login since // CSRF against the login form makes no sense and the login form does a // cookies-enabled check which would break otherwise. if (IsPost() && GetParam("_CSRF_Check") != GetCSRFCheck() && sURI != "/login") { DEBUG("Expected _CSRF_Check: " << GetCSRFCheck()); DEBUG("Actual _CSRF_Check: " << GetParam("_CSRF_Check")); PrintErrorPage(403, "Access denied", "POST requests need to send " "a secret token to prevent cross-site request forgery attacks."); return PAGE_DONE; } SendCookie("SessionId", GetSession()->GetId()); if (GetSession()->IsLoggedIn()) { m_sUser = GetSession()->GetUser()->GetUserName(); m_bLoggedIn = true; } // Handle the static pages that don't require a login if (sURI == "/") { if(!m_bLoggedIn && GetParam("cookie_check", false).ToBool() && GetRequestCookie("SessionId").empty()) { GetSession()->AddError("Your browser does not have cookies enabled for this site!"); } return PrintTemplate("index", sPageRet); } else if (sURI == "/favicon.ico") { return PrintStaticFile("/pub/favicon.ico", sPageRet); } else if (sURI == "/robots.txt") { return PrintStaticFile("/pub/robots.txt", sPageRet); } else if (sURI == "/logout") { GetSession()->SetUser(NULL); SetLoggedIn(false); Redirect("/"); // We already sent a reply return PAGE_DONE; } else if (sURI == "/login") { if (GetParam("submitted").ToBool()) { m_sUser = GetParam("user"); m_sPass = GetParam("pass"); m_bLoggedIn = OnLogin(m_sUser, m_sPass); // AcceptedLogin()/RefusedLogin() will call Redirect() return PAGE_DEFERRED; } Redirect("/"); // the login form is here return PAGE_DONE; } else if (sURI.Left(5) == "/pub/") { return PrintStaticFile(sURI, sPageRet); } else if (sURI.Left(11) == "/skinfiles/") { CString sSkinName = sURI.substr(11); CString::size_type uPathStart = sSkinName.find("/"); if (uPathStart != CString::npos) { CString sFilePath = sSkinName.substr(uPathStart + 1); sSkinName.erase(uPathStart); m_Template.ClearPaths(); m_Template.AppendPath(GetSkinPath(sSkinName) + "pub"); if (PrintFile(m_Template.ExpandFile(sFilePath))) { return PAGE_DONE; } else { return PAGE_NOTFOUND; } } return PAGE_NOTFOUND; } else if (sURI.Left(6) == "/mods/" || sURI.Left(10) == "/modfiles/") { ParsePath(); // Make sure modules are treated as directories if (sURI.Right(1) != "/" && sURI.find(".") == CString::npos && sURI.TrimLeft_n("/mods/").TrimLeft_n("/").find("/") == CString::npos) { Redirect(sURI + "/"); return PAGE_DONE; } CModule *pModule = CZNC::Get().GetModules().FindModule(m_sModName); if (!pModule) { // Check if GetSession()->GetUser() is NULL and display // an error in that case if (!ForceLogin()) return PAGE_DONE; pModule = GetSession()->GetUser()->GetModules().FindModule(m_sModName); } if (!pModule) { return PAGE_NOTFOUND; } else if (pModule->WebRequiresLogin() && !ForceLogin()) { return PAGE_PRINT; } else if (pModule->WebRequiresAdmin() && !GetSession()->IsAdmin()) { PrintErrorPage(403, "Forbidden", "You need to be an admin to access this module"); return PAGE_DONE; } else if (!pModule->IsGlobal() && pModule->GetUser() != GetSession()->GetUser()) { PrintErrorPage(403, "Forbidden", "You must login as " + pModule->GetUser()->GetUserName() + " in order to view this page"); return PAGE_DONE; } else if (pModule->OnWebPreRequest(*this, m_sPage)) { return PAGE_DEFERRED; } VWebSubPages& vSubPages = pModule->GetSubPages(); for (unsigned int a = 0; a < vSubPages.size(); a++) { TWebSubPage& SubPage = vSubPages[a]; bool bActive = (m_sModName == pModule->GetModName() && m_sPage == SubPage->GetName()); if (bActive && SubPage->RequiresAdmin() && !GetSession()->IsAdmin()) { PrintErrorPage(403, "Forbidden", "You need to be an admin to access this page"); return PAGE_DONE; } } if (pModule && !pModule->IsGlobal() && (!IsLoggedIn() || pModule->GetUser() != GetSession()->GetUser())) { AddModLoop("UserModLoop", *pModule); } if (sURI.Left(10) == "/modfiles/") { m_Template.AppendPath(GetSkinPath(GetSkinName()) + "/mods/" + m_sModName + "/files/"); m_Template.AppendPath(pModule->GetModDataDir() + "/files/"); if (PrintFile(m_Template.ExpandFile(m_sPage.TrimLeft_n("/")))) { return PAGE_PRINT; } else { return PAGE_NOTFOUND; } } else { SetPaths(pModule, true); /* if a module returns false from OnWebRequest, it does not want the template to be printed, usually because it did a redirect. */ if (pModule->OnWebRequest(*this, m_sPage, m_Template)) { // If they already sent a reply, let's assume // they did what they wanted to do. if (SentHeader()) { return PAGE_DONE; } return PrintTemplate(m_sPage, sPageRet, pModule); } if (!SentHeader()) { PrintErrorPage(404, "Not Implemented", "The requested module does not acknowledge web requests"); } return PAGE_DONE; } } else { CString sPage(sURI.Trim_n("/")); if (sPage.length() < 32) { for (unsigned int a = 0; a < sPage.length(); a++) { unsigned char c = sPage[a]; if ((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_') { return PAGE_NOTFOUND; } } return PrintTemplate(sPage, sPageRet); } } return PAGE_NOTFOUND; }
void RedirectStdout(const char *stdout_path) { Redirect(stdout_path, STDOUT_FILENO, "stdout"); }
sysProcess::sysProcess(wxEvtHandler *evh, wxMBConv &conv) : wxProcess(evh), m_conv(conv) { pid = 0; Redirect(); }
void RedirectStderr(const char *stderr_path) { Redirect(stderr_path, STDERR_FILENO, "stderr"); }