bool ESP8266WebServerEx::VerifyCookie(const char* mime) { if ( !hasLogin || strcmp(mime,"text/html")!=0 ) return true; String session = GetSessionId(); long tag = -1; if ( session.length()==32 && g_Session.isValid(session,&tag) ) { if ( tag>0 && tag<10 ) { SetSessionId(session); return true; } } redirect("/"); return false; }
int main() { /* redirect the standand IO to /dev/tty */ if (redirect(STDOUT_FILENO, "/dev/tty", O_WRONLY | O_CREAT) == -1) { return -1; } if (redirect(STDIN_FILENO, "/dev/tty", O_RDONLY) == -1) { return -1; } while (1) { char line[256]; /* assume the longest command will have less than 256 characters */ char *command; printf ("utdash$ "); fgets(line, sizeof(line), stdin); command = trim(line); process(command); } return 0; }
int main(int argc, char *argv[], char *envp[]) { int oldPipe[2]; int newPipe[2]; printf("$ \n"); /* For the pipe test, the parent will feed the child. */ /* In live shell usage, this next line won't exist. */ pid = 1; int i; for(i = 0; i < 4; i++){ if(pid){ pipe(newPipe); redirect(oldPipe, newPipe); } } newPipe[0] = 0; newPipe[1] = 0; redirect(oldPipe, newPipe); /* This child should print to stdout. */ if(pid){ printf("Multi-pipe test successful.\n"); while(waitpid(-1,return_status) != -1){}; /* Wait until all processes finish. */ } return 0; }
MetaProcessor::MaybeRedirectOutputRAII::MaybeRedirectOutputRAII( MetaProcessor* p) :m_MetaProcessor(p), m_isCurrentlyRedirecting(0) { StringRef redirectionFile; m_MetaProcessor->increaseRedirectionRAIILevel(); if (!m_MetaProcessor->m_PrevStdoutFileName.empty()) { redirectionFile = m_MetaProcessor->m_PrevStdoutFileName.back(); redirect(stdout, redirectionFile.str(), kSTDOUT); } if (!m_MetaProcessor->m_PrevStderrFileName.empty()) { redirectionFile = m_MetaProcessor->m_PrevStderrFileName.back(); // Deal with the case 2>&1 and 2&>1 if (strcmp(redirectionFile.data(), "_IO_2_1_stdout_") == 0) { // If out is redirected to a file. if (!m_MetaProcessor->m_PrevStdoutFileName.empty()) { redirectionFile = m_MetaProcessor->m_PrevStdoutFileName.back(); } else { unredirect(m_MetaProcessor->m_backupFDStderr, STDERR_FILENO, stderr); } } redirect(stderr, redirectionFile.str(), kSTDERR); } }
PatchGrid& PatchGrid::operator=(const PatchGrid& grid) { Grid::operator=(grid); ntilex = grid.ntilex; ntiley = grid.ntiley; ntiles = grid.ntiles; if (~spec & abstract) { unmake(); make(); } else { redirect(); } return *this; }
void NavigationScheduler::timerFired(Timer<NavigationScheduler>*) { if (!m_frame->page()) return; if (m_frame->page()->defersLoading()) { InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); return; } Ref<Frame> protect(*m_frame); OwnPtr<ScheduledNavigation> redirect(m_redirect.release()); redirect->fire(m_frame); InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); }
void StdOutputRedirector::init(const Arguments & theArguments) { if (theArguments.haveOption("--std-logfile")) { const char * myEnv = ::getenv(LOG_WRAPAROUND_FILESIZE); if (myEnv) { string mylogFileSize(myEnv); _myMaximumFileSize = asl::as<long>(mylogFileSize); } myEnv = ::getenv(LOG_CREATE_ON_EACH_RUN); if (myEnv) { string myTmpStr(myEnv); _myLogInOneFileFlag = !(strcmp(toLowerCase(myTmpStr).c_str(), "true") == 0); } myEnv = ::getenv(LOG_REMOVE_OLD_ARCHIVE); if (myEnv) { string myTmpStr(myEnv); _myRemoveOldArchiveFlag = (strcmp(toLowerCase(myTmpStr).c_str(), "true") == 0); } myEnv = ::getenv(LOG_WRAPAROUND_CHECK_SEC); if (myEnv) { string myTmpStr(myEnv); _myFileSizeCheckFrequInSec = asl::as<long>(myTmpStr); } std::string myFilenameWithTimestamp = expandString(theArguments.getOptionArgument("--std-logfile"), _myOutputFilename); if (!_myLogInOneFileFlag) { _myOutputFilename = myFilenameWithTimestamp; } // for syncing c like stderr & c++ cerr // default is true, not syncing is supposted to be faster, so maybe we should disable it //ios_base::sync_with_stdio(false); redirect(); // write a timestamp cout << ourAppStartMessage << _myOutputFilename << endl; cout << "Timestamp: " << getCurrentTimeString() << endl; cout << "---------" << endl; // remove all but latest archives if (_myRemoveOldArchiveFlag) { removeoldArchives(); } } }
/* Common base run for every request. */ static void commonBase(HttpStream *stream) { cchar *uri; if (!httpIsAuthenticated(stream)) { /* Access to certain pages are permitted without authentication so the user can login and logout. */ uri = getUri(); if (sstarts(uri, "/public/") || smatch(uri, "/user/login") || smatch(uri, "/user/logout")) { return; } feedback("error", "Access Denied. Login required."); redirect("/public/login.esp"); } }
QNetworkReply *PythonQtDecorator::syncGet(QNetworkAccessManager *self, QNetworkRequest request) { QNetworkReply *reply; QEventLoop loop; do { // Request reply = self->get(request); connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); loop.exec(); } while (redirect(reply, request)); return reply; }
/***************************************************************************//** * @author Hayden Waisanen * * @par Description: * This function temporarily redirect STD_IN or STD_OUT to a file, specified * in the file_name parameter. Must be followed by a restore method call to * restore output or input. * * @par Class: * Reroute * * @param[in] int file_no - Redirect STDIN, 0, or STDOUT, 1 * @param[in] int input_pipe[] - pipe to redirect * * @returns bool - success or failure * ******************************************************************************/ bool Reroute::redirect(int file_no, string ip, string port) { //Creae a socket for port and ip int sockfd = createSocket(ip, port); bool return_val; //Temporary storage for redirect return value //Check for a valid socket file descriptor if(sockfd < 0) { return false; } //Call redirect and return return_val = redirect(file_no, sockfd); return return_val; }
// Executes a <simple> redirection. If background == true, the command is // executed in the background. Returns the <simple>'s status, or 0 if background // is true and we don't wait for it to die. int processSimple(CMD* cmd, bool background) { if(IS_BUILTIN(cmd->argv[0])) { int status = execBuiltin(cmd); updateStatusVar(status); return status; } int pid; if((pid = fork()) < 0) { // error in forking perror(EXEC_NAME); return errno; } else if(pid == 0) { // child if(redirect(cmd) < 0) { exit(errno); } execvp(cmd->argv[0], cmd->argv); perror(EXEC_NAME); exit(EXIT_FAILURE); } else { // parent if(background) { return 0; } else { int status; signal(SIGINT, SIG_IGN); waitpid(pid, &status, 0); signal(SIGINT, SIG_DFL); int exitStatus = GET_STATUS(status); updateStatusVar(exitStatus); return exitStatus; } } }
int exec_cmd(cmd *command) { pid_t *pids = malloc(command->p_len * sizeof(pid_t)); int status, i; int fds[2][2]; cmd *cmdp; status = pipe(fds[1]); // reduce complexity in the following code //fprintf(stderr, "p_len: %d\n", command->p_len); for (cmdp = command, i = 0; i < command->p_len; cmdp = cmdp->cmd_next, i++) { status = pipe(fds[i % 2]); if (status < 0) { perror("shell: pipe"); exit(127); } if ((pids[i] = fork()) < 0) { perror("shell: fork"); exit(127); } else if (pids[i] == 0) { // child process signal(SIGTSTP, SIG_DFL); signal(SIGINT, SIG_DFL); signal(SIGCONT, SIG_DFL); if (i != command->p_len-1) // not the first command in pipeline, redirect stdin dup2(fds[i%2][0], STDIN_FILENO); if (i != 0) // not the last command in pipeline, redirect stdout dup2(fds[!(i%2)][1], STDOUT_FILENO); close(fds[0][0]); close(fds[0][1]); close(fds[1][0]); close(fds[1][1]); redirect(cmdp); //fprintf(stderr, "exec: %d %d %s\n", i, (int)cmdp, cmdp->argv[0]); execvp(cmdp->argv[0], cmdp->argv); fputs("shell: ", stderr); perror(cmdp->argv[0]); exit(127); } else { // parent process close(fds[!(i%2)][0]); close(fds[!(i%2)][1]); } } //printf("pid: %d\n", pids[0]); if (command->bg) { jobctl_add_job(pids[0], buf, JOBCTL_RUN, 1); } else { waitcmd(pids[0], buf); } free(pids); return status; }
void TextCtrlTestCase::Redirector() { #if wxHAS_TEXT_WINDOW_STREAM && wxUSE_STD_IOSTREAM wxStreamToTextRedirector redirect(m_text); std::cout << "stringinput" << 10 << 1000L << 3.14f << 2.71 << 'a'; CPPUNIT_ASSERT_EQUAL("stringinput1010003.142.71a", m_text->GetValue()); #endif }
void NavigationScheduler::navigateTask() { Platform::current()->currentThread()->scheduler()->removePendingNavigation(); if (!m_frame->page()) return; if (m_frame->page()->defersLoading()) { InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); return; } RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); OwnPtrWillBeRawPtr<ScheduledNavigation> redirect(m_redirect.release()); redirect->fire(m_frame); InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); }
void EntryController::create() { if (httpRequest().method() != Tf::Post) { return; } Entry entry = Entry::create( httpRequest().formItems("entry") ); if (!entry.isNull()) { QString notice = "Created successfully."; tflash(notice); redirect(urla("show", entry.id())); } else { QString error = "Failed to create."; texport(error); render("entry"); } }
int bbssel_main() { char *board, buf[80], *board1, *title; int i, total = 0; html_header(1); check_msg(); changemode(SELECT); board = nohtml(getparm("board")); if (board[0] == 0) { printf("%s -- 选择讨论区<hr>\n", BBSNAME); printf("<form action=bbssel>\n"); printf("讨论区名称: <input type=text name=board>"); printf(" <input type=submit value=确定>"); printf("</form>\n"); http_quit(); } else { struct boardmem *x; x = getboard(board); if (x) { sprintf(buf, "%s%s", showByDefMode(), x->header.filename); redirect(buf); http_quit(); } printf("%s -- 选择讨论区<hr>\n", BBSNAME); printf("找不到这个讨论区, ", board); printf("标题中含有'%s'的讨论区有: <br><br>\n", board); printf("<table>"); for (i = 0; i < MAXBOARD && i < shm_bcache->number; i++) { board1 = shm_bcache->bcache[i].header.filename; title = shm_bcache->bcache[i].header.title; if (!has_read_perm(¤tuser, board1)) continue; if (strcasestr(board1, board) || strcasestr(title, board)) { total++; printf("<tr><td>%d", total); printf ("<td><a href=%s%s>%s</a><td>%s<br>\n", showByDefMode(), board1, board1, title + 7); } } printf("</table><br>\n"); printf("共找到%d个符合条件的讨论区.\n", total); } }
/** * 初期化処理 * * @return なし */ void cut_startup(void) { set_sig_handler(); /* バッファリングしない */ if (setvbuf(stdin, NULL, _IONBF, 0)) cut_notify("setvbuf: stdin(%d)", errno); if (setvbuf(stdout, NULL, _IONBF, 0)) cut_notify("setvbuf: stdout(%d)", errno); (void)memset(&server, 0, sizeof(testserver)); test_init_server(&server); /* リダイレクト */ redirect(STDERR_FILENO, "/dev/null"); }
FILE *fopen64(const char *pathname, const char *mode) { FILE *fp; const char *path; char buffer[PATH_MAX]; fopen64_func_t orig_fopen64; orig_fopen64 = (fopen64_func_t)dlsym(RTLD_NEXT, "fopen64"); path = redirect(pathname, buffer); fp = orig_fopen64(path, mode); if (path != pathname && getenv("PRELOAD_DEBUG")) { fprintf(stderr, "preload_debug: fopen64(\"%s\", \"%s\") => \"%s\": fp=%p\n", pathname, mode, path, fp); } return fp; }
/***************************************************************************//** * @author Hayden Waisanen * * @par Description: * This function creates a remote output socket for the specifed port. * Function call must be eventually followed with a restore call to return * output to stdout * * @par Class: * Reroute * * @param[in] int file_no - Redirect STDIN, 0, or STDOUT, 1 * @param[in] string port - Port to output to * * @returns bool - success or failure * ******************************************************************************/ bool Reroute::redirect_remote(int file_no, string port) { int remote_fd; //File descriptor of remote connection bool return_val; //Temporary storage for redirect return value remote_fd = listenForSocket(port); // Wait for a connection //Check for a valid file descriptor if(remote_fd < 0) { cout << "Unable to open socket." << endl; return false; } //Redirect to this file descriptor, and close the useless descriptor return_val = redirect(file_no, remote_fd); close(remote_fd); return return_val; }
void ParksController::create() { if (httpRequest().method() != Tf::Post) { return; } auto form = httpRequest().formItems("parks"); auto parks = Parks::create(form); if (!parks.isNull()) { QString notice = "Created successfully."; tflash(notice); redirect(urla("show", parks.id())); } else { QString error = "Failed to create."; texport(error); renderEntry(form); } }
void AssetsunitmanagerController::create() { if (httpRequest().method() != Tf::Post) { return; } auto form = httpRequest().formItems("assetsunitmanager"); auto assetsunitmanager = Assetsunitmanager::create(form); if (!assetsunitmanager.isNull()) { QString notice = "Created successfully."; tflash(notice); redirect(urla("Cms/list_manager")); } else { QString error = "Failed to create."; texport(error); renderEntry(form); } }
void MarketingunitController::create() { if (httpRequest().method() != Tf::Post) { return; } auto form = httpRequest().formItems("marketingunit"); auto marketingunit = Marketingunit::create(form); if (!marketingunit.isNull()) { QString notice = "Created successfully."; tflash(notice); redirect(urla("show", marketingunit.muid())); } else { QString error = "Failed to create."; texport(error); renderEntry(form); } }
ExtScript *ExtScript::copy(const QString _fileName, const int _number) { qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number; ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName, directories()); item->setActive(isActive()); item->setApiVersion(apiVersion()); item->setComment(comment()); item->setExecutable(executable()); item->setInterval(interval()); item->setName(name()); item->setNumber(_number); item->setPrefix(prefix()); item->setRedirect(redirect()); return item; }
static void searchlist_grouped(char *match, int dored) { int i, count = 0, bnum = 0; for (i = 0; i < sectree.nsubsec; i++) { count += searchlist_alphabetical(sectree.subsec[i]->title, sectree.subsec[i]->basestr, match, *match, &bnum); } if (!count) { printf("Ò»¸ö¶¼Ã»ÕÒµ½£¬»»¸ö¹Ø¼ü´ÊÊÔÊÔ£¿"); } else if (count == 1 && dored) { char buf[80]; sprintf(buf, "home?B=%d", bnum); if (!(shm_bcache->bcache[bnum].header.flag & CLOSECLUB_FLAG)) redirect(buf); } }
void WorldController::create() { if (httpRequest().method() != Tf::Post) { return; } QVariantMap form = httpRequest().formItems("world"); World world = World::create(form); if (!world.isNull()) { QString notice = "Created successfully."; tflash(notice); redirect(urla("show", world.id())); } else { QString error = "Failed to create."; texport(error); renderEntry(form); } }
static unsigned int execute(fork_func_param_t param) { /* Cast argument */ struct worker_params *params = (struct worker_params *) param; /* We dont need the read end of the pipe */ close_pipe(params->pipe, channel_read); /* Redirect stdout to write end */ if(redirect(params->pipe, stdout, channel_write) == -1) { return 1; } /* We use sh here, to circumvent parsing the command string */ (void) execlp("/bin/sh", "sh", "-c", params->cmd, (char *) NULL); // Should not be reached; return 1; }
int apply(my_tab t) { my_tab tt = NULL; my_tab tc = r_cp(t);; int i = 0; while (my_tlen(tc) > 0) { tt = r_first(tc, ";"); if (is_redirect(t)) i = redirect(tt); else i = i_call(tt); my_tfree(tt); if (i != 0) break; } my_tfree(tc); return i; }
void CmsController::createmanager() { QString adminID = session().value("adminID").toString(); if (httpRequest().method() != Tf::Post) { return; } auto form = httpRequest().formItems("assetsunitmanager"); QString managerID = form["managerID"].toString(); Assetsunitmanager a; auto assetsunitmanager = a.create(form); if(!assetsunitmanager.isNull() && a.new_manager(adminID,managerID)){ // QString adminID = session().value("adminID").toString(); redirect(urla("list_manager")); }else{ QString error = "资产管理人编号已经存在!"; texport(error); renderEntry2(form); } }
STATIC void evalsubshell(union node *n, int flags) { struct job *jp; int backgnd = (n->type == NBACKGND); expredir(n->nredir.redirect); jp = makejob(n, 1); if (forkshell(jp, n, backgnd) == 0) { if (backgnd) flags &=~ EV_TESTED; redirect(n->nredir.redirect, 0); evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */ } if (! backgnd) { INTOFF; exitstatus = waitforjob(jp, (int *)NULL); INTON; } }
static void evalsubshell(union node *n, int flags) { struct job *jp; int backgnd = (n->type == NBACKGND); oexitstatus = exitstatus; expredir(n->nredir.redirect); if ((!backgnd && flags & EV_EXIT && !have_traps()) || forkshell(jp = makejob(n, 1), n, backgnd) == 0) { if (backgnd) flags &=~ EV_TESTED; redirect(n->nredir.redirect, 0); evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */ } else if (! backgnd) { INTOFF; exitstatus = waitforjob(jp, (int *)NULL); INTON; } }