void run_server_or_cgi::run() { bool server=false; for (int i=1; i<argc; i++) if (argv[i]==string("-s")|| argv[i]==string("--server")) server=true; if (server){ run_server(c, argc, argv).run(); } else{ bool help=false; for (int i=1; i<argc; i++) if (argv[i]==string("-h")|| argv[i]==string("--help")) help=true; if (help){ cerr<<"usage: "<<argv[0]<<" [-s] [-h] [server-options]"<<endl; exit(0); } run_cgi(c).run(); } }
/* * Handle file selectors */ void gopher_file(state *st) { struct stat file; char buf[BUFSIZE]; char *c; /* Refuse to serve out gophermaps/tags */ if ((c = strrchr(st->req_realpath, '/'))) c++; else c = st->req_realpath; if (strcmp(c, st->map_file) == MATCH) die(st, ERR_ACCESS, "Refusing to serve out a gophermap file"); if (strcmp(c, st->tag_file) == MATCH) die(st, ERR_ACCESS, "Refusing to serve out a gophertag file"); /* Check for & run CGI and query scripts */ if (strstr(st->req_realpath, st->cgi_file) || st->req_filetype == TYPE_QUERY) run_cgi(st, st->req_realpath, NULL); /* Check for a file suffix filter */ if (*st->filter_dir && (c = strrchr(st->req_realpath, '.'))) { snprintf(buf, sizeof(buf), "%s/%s", st->filter_dir, c + 1); /* Filter file through the script */ if (stat(buf, &file) == OK && (file.st_mode & S_IXOTH)) run_cgi(st, buf, st->req_realpath); } /* Check for a filetype filter */ if (*st->filter_dir) { snprintf(buf, sizeof(buf), "%s/%c", st->filter_dir, st->req_filetype); /* Filter file through the script */ if (stat(buf, &file) == OK && (file.st_mode & S_IXOTH)) run_cgi(st, buf, st->req_realpath); } /* Output regular files */ if (st->req_filetype == TYPE_TEXT || st->req_filetype == TYPE_MIME) send_text_file(st); else send_binary_file(st); }
virtual int cgi_main(int argc, char_t** argv, char_t** env) { int err = 0, err2 = 0; if (!(err = before_get_cgi_form(argc, argv, env))) { if (!(err = get_cgi_form(argc, argv, env))) { if (!(err = before_run_cgi(argc, argv, env))) { if (!(err = run_cgi(argc, argv, env))) { } if ((err2 = after_run_cgi(argc, argv, env)) && (!err)) { err = err2; } } } if ((err2 = after_get_cgi_form(argc, argv, env)) && (!err)) { err = err2; } } return err; }
virtual int run_console(int argc, char_t** argv, char_t** env) { int err = run_cgi(argc, argv, env); return err; }