void handle(int fd) { char buf[200]; ssize_t n_read; while((n_read = read(fd, buf, sizeof(buf))) > 0) { buf[n_read-1] = '\0'; char* bufp = buf; char* cursor; while((cursor = strsep(&bufp, "\n")) != NULL) { int fdd = dup(fd); FILE* f = fdopen(fdd, "a"); char command[20]; char const* const remainder = flatjson_next(chomp(buf), command, sizeof(command), NULL); if(strcmp(command, "list") == 0) { handle_list(f, true); } else if(strcmp(command, "configure") == 0) { handle_configure(f, remainder); } else if(strcmp(command, "connect") == 0) { handle_connect(f, remainder); } else if(strcmp(command, "disconnect") == 0) { handle_disconnect(f, remainder); } else { warn("Unknown command"); } fclose(f); } } }
// Handle's a client's request // @param connectionfd the descriptor for the connection // @param server the database server // @param command the type of request // @param client the client's information // @return 1 if the server should handle another request, -1 otherwise int handle_request(int connectionfd, char *server, char **command, client_info **client) { // Check if the client used the correct protocol if (read_request(connectionfd, &(*client)->username, &(*client)->password, &(*client)->token, &(*client)->list, command) == 1) { // The client sent an 'Auth' request if (strcmp(*command, COMMAND_AUTH) == 0) { // Attempt to authenticate the client with the Hooli database if (handle_auth(connectionfd, server, command, &(*client)->username, &(*client)->password) == -1) { return -1; } //end if } //end if // The client sent a 'List' request else if (strcmp(*command, COMMAND_LIST) == 0) { // Attempt to sync the client with the Hooli database if (handle_list(connectionfd, server, command, &(*client)->token, &(*client)->response_list, (*client)->list) == -1) { return -1; } //end if } //end else if // The client gave an invalid command else { syslog(LOG_DEBUG, "Expected valid command, got '%s'", *command); response_401(connectionfd); return -1; } //end else } //end if // The client's message did not follow the protocol else { syslog(LOG_DEBUG, "Received message failed to follow protocol"); response_401(connectionfd); return -1; } //end else return 1; } //end handle_request
mclx* handle_query ( mclx* mx , mcxIO* xfmx , mcxTing* sa , mcxTing* sb ) { if (!strcmp(sa->str, ":top")) handle_top(mx, sb) ; else if (!strcmp(sa->str, ":list")) handle_list(mx, sb) ; else if (!strcmp(sa->str, ":reread")) { mclxFree(&mx) ; if (xfabc_g) { streamer_g.tab_sym_in = tab_g ; mx = mclxIOstreamIn ( xfabc_g , MCLXIO_STREAM_ABC | (input_status != 'd' ? MCLXIO_STREAM_MIRROR : 0) | MCLXIO_STREAM_SYMMETRIC | MCLXIO_STREAM_GTAB_RESTRICT /* docme/fixme need to check for tab_g ? */ , NULL , mclpMergeMax , &streamer_g /* has tab, if present */ , EXIT_ON_FAIL ) ; mcxIOclose(xfabc_g) ; } else { mx = mclxReadx (xfmx, EXIT_ON_FAIL, MCLX_REQUIRE_GRAPH | MCLX_REQUIRE_CANONICAL) ; mcxIOclose(xfmx) ; } mclxAdjustLoops(mx, mclxLoopCBremove, NULL) ; } else if (!strcmp(sa->str, ":clcf")) handle_clcf(mx, sb) ; else if (!strcmp(sa->str, ":tf")) { handle_tf(mx, sb) ; mcxTell(me, "graph now has %lu arcs", (ulong) mclxNrofEntries(mx)) ; } else fprintf(stderr, "(error unknown-query (:clcf#1 :list#1 :reread :top#1))\n") ; return mx ; }
void process_post_login(struct vsf_session* p_sess) { int retval; if (p_sess->is_anonymous) { vsf_sysutil_set_umask(tunable_anon_umask); p_sess->bw_rate_max = tunable_anon_max_rate; } else { vsf_sysutil_set_umask(tunable_local_umask); p_sess->bw_rate_max = tunable_local_max_rate; } if (tunable_async_abor_enable) { vsf_sysutil_install_sighandler(kVSFSysUtilSigURG, handle_sigurg, p_sess); vsf_sysutil_activate_sigurg(VSFTP_COMMAND_FD); } /* Kitsune */ vsf_sysutil_kitsune_set_update_point("postlogin.c"); if(!kitsune_is_updating()) { /* Handle any login message */ vsf_banner_dir_changed(p_sess, FTP_LOGINOK); vsf_cmdio_write(p_sess, FTP_LOGINOK, "Login successful. Have fun."); } else { /* Set sigchld function pointer (normally done in twoprocess.c) */ vsf_sysutil_default_sig(kVSFSysUtilSigCHLD); vsf_sysutil_install_async_sighandler(kVSFSysUtilSigCHLD, twoproc_handle_sigchld); } /* End Kitsune */ while(1) { if (tunable_setproctitle_enable) { vsf_sysutil_setproctitle("IDLE"); } /* Kitsune update point */ kitsune_update("postlogin.c"); /**DSU updatepoint */ /* Blocks */ vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str, &p_sess->ftp_arg_str, 1); if (tunable_setproctitle_enable) { struct mystr proctitle_str = INIT_MYSTR; str_copy(&proctitle_str, &p_sess->ftp_cmd_str); if (!str_isempty(&p_sess->ftp_arg_str)) { str_append_char(&proctitle_str, ' '); str_append_str(&proctitle_str, &p_sess->ftp_arg_str); } /* Suggestion from Solar */ str_replace_unprintable(&proctitle_str, '?'); vsf_sysutil_setproctitle_str(&proctitle_str); str_free(&proctitle_str); } if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT")) { vsf_cmdio_write(p_sess, FTP_GOODBYE, "Goodbye."); vsf_sysutil_exit(0); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PWD") || str_equal_text(&p_sess->ftp_cmd_str, "XPWD")) { handle_pwd(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "CWD") || str_equal_text(&p_sess->ftp_cmd_str, "XCWD")) { handle_cwd(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "CDUP") || str_equal_text(&p_sess->ftp_cmd_str, "XCUP")) { handle_cdup(p_sess); } else if (tunable_pasv_enable && str_equal_text(&p_sess->ftp_cmd_str, "PASV")) { handle_pasv(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "RETR")) { handle_retr(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "NOOP")) { vsf_cmdio_write(p_sess, FTP_NOOPOK, "NOOP ok."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SYST")) { vsf_cmdio_write(p_sess, FTP_SYSTOK, "UNIX Type: L8"); } else if (str_equal_text(&p_sess->ftp_cmd_str, "HELP")) { vsf_cmdio_write(p_sess, FTP_BADHELP, "Sorry, I don't have help."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "LIST")) { handle_list(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "TYPE")) { handle_type(p_sess); } else if (tunable_port_enable && str_equal_text(&p_sess->ftp_cmd_str, "PORT")) { handle_port(p_sess); } else if (tunable_write_enable && (tunable_anon_upload_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "STOR")) { handle_stor(p_sess); } else if (tunable_write_enable && (tunable_anon_mkdir_write_enable || !p_sess->is_anonymous) && (str_equal_text(&p_sess->ftp_cmd_str, "MKD") || str_equal_text(&p_sess->ftp_cmd_str, "XMKD"))) { handle_mkd(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && (str_equal_text(&p_sess->ftp_cmd_str, "RMD") || str_equal_text(&p_sess->ftp_cmd_str, "XRMD"))) { handle_rmd(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "DELE")) { handle_dele(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "REST")) { handle_rest(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "RNFR")) { handle_rnfr(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "RNTO")) { handle_rnto(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "NLST")) { handle_nlst(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SIZE")) { handle_size(p_sess); } else if (!p_sess->is_anonymous && str_equal_text(&p_sess->ftp_cmd_str, "SITE")) { handle_site(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "ABOR")) { vsf_cmdio_write(p_sess, FTP_ABOR_NOCONN, "No transfer to ABOR."); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "APPE")) { handle_appe(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "MDTM")) { handle_mdtm(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PASV") || str_equal_text(&p_sess->ftp_cmd_str, "PORT") || str_equal_text(&p_sess->ftp_cmd_str, "STOR") || str_equal_text(&p_sess->ftp_cmd_str, "MKD") || str_equal_text(&p_sess->ftp_cmd_str, "XMKD") || str_equal_text(&p_sess->ftp_cmd_str, "RMD") || str_equal_text(&p_sess->ftp_cmd_str, "XRMD") || str_equal_text(&p_sess->ftp_cmd_str, "DELE") || str_equal_text(&p_sess->ftp_cmd_str, "RNFR") || str_equal_text(&p_sess->ftp_cmd_str, "RNTO") || str_equal_text(&p_sess->ftp_cmd_str, "SITE") || str_equal_text(&p_sess->ftp_cmd_str, "APPE")) { vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied."); } else { vsf_cmdio_write(p_sess, FTP_BADCMD, "Unknown command."); } } }
static int handle(char *buf) { TCSession *session = tc_get_session(); char *cmd, *params; int len, retval; len = strlen(buf); if (len > 0 && buf[len-1] == '\n') buf[--len] = 0; if (len > 0 && buf[len-1] == '\r') buf[--len] = 0; //tc_log_msg(__FILE__, "read from socket: |%s|", buf); cmd = buf + strspn(buf, " \t"); params = cmd + strcspn(cmd, " \t"); *params++ = 0; params += strspn(params, " \t"); if (!*cmd) { // not strictly necessary, but lines up else if's nicely retval = 0; } else if (strncasecmp(cmd, "config", 2) == 0) { retval = handle_config(params); } else if (strncasecmp(cmd, "disable", 2) == 0) { retval = handle_disable(params); } else if (strncasecmp(cmd, "dump", 2) == 0) { dump_vob(client_sock); retval = 1; } else if (strncasecmp(cmd, "enable", 2) == 0) { retval = handle_enable(params); } else if (strncasecmp(cmd, "help", 2) == 0) { retval = handle_help(params); } else if (strncasecmp(cmd, "list", 2) == 0) { retval = handle_list(params); } else if (strncasecmp(cmd, "load", 2) == 0) { retval = handle_load(params); } else if (strncasecmp(cmd, "parameters", 3) == 0) { retval = handle_parameter(params); } else if (strncasecmp(cmd, "pause", 3) == 0) { tc_pause_request(); retval = 1; } else if (strncasecmp(cmd, "preview", 3) == 0) { retval = handle_preview(params); } else if (strncasecmp(cmd, "progress", 5) == 0) { session->progress_meter = !session->progress_meter; retval = 1; } else if (strncasecmp(cmd, "processing", 10) == 0) { dump_processing(client_sock); retval = 1; } else if (strncasecmp(cmd, "quit", 2) == 0 || strncasecmp(cmd, "exit", 2) == 0) { return 0; // tell caller to close socket } else if (strncasecmp(cmd, "unload", 2) == 0) { retval = 0; // FIXME: not implemented } else if (strncasecmp(cmd, "version", 2) == 0) { sendstr(client_sock, PACKAGE_VERSION "\n"); retval = 1; } else if (strncasecmp(cmd, "stop", 4)) { tc_interrupt(); tc_framebuffer_interrupt(); retval = 1; } else { retval = 0; } sendstr(client_sock, retval ? "OK\n" : "FAILED\n"); return 1; // socket remains open }
void process_post_login(struct vsf_session* p_sess) { if (p_sess->is_anonymous) { vsf_sysutil_set_umask(tunable_anon_umask); p_sess->bw_rate_max = tunable_anon_max_rate; } else { vsf_sysutil_set_umask(tunable_local_umask); p_sess->bw_rate_max = tunable_local_max_rate; } if (tunable_async_abor_enable) { vsf_sysutil_install_sighandler(kVSFSysUtilSigURG, handle_sigurg, p_sess); vsf_sysutil_activate_sigurg(VSFTP_COMMAND_FD); } /* Handle any login message */ vsf_banner_dir_changed(p_sess, FTP_LOGINOK); vsf_cmdio_write(p_sess, FTP_LOGINOK, "Login successful."); while(1) { int cmd_ok = 1; if (tunable_setproctitle_enable) { vsf_sysutil_setproctitle("IDLE"); } /* Blocks */ vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str, &p_sess->ftp_arg_str, 1); if (tunable_setproctitle_enable) { struct mystr proctitle_str = INIT_MYSTR; str_copy(&proctitle_str, &p_sess->ftp_cmd_str); if (!str_isempty(&p_sess->ftp_arg_str)) { str_append_char(&proctitle_str, ' '); str_append_str(&proctitle_str, &p_sess->ftp_arg_str); } /* Suggestion from Solar */ str_replace_unprintable(&proctitle_str, '?'); vsf_sysutil_setproctitle_str(&proctitle_str); str_free(&proctitle_str); } /* Test command against the allowed list.. */ if (tunable_cmds_allowed) { static struct mystr s_src_str; static struct mystr s_rhs_str; str_alloc_text(&s_src_str, tunable_cmds_allowed); while (1) { str_split_char(&s_src_str, &s_rhs_str, ','); if (str_isempty(&s_src_str)) { cmd_ok = 0; break; } else if (str_equal(&s_src_str, &p_sess->ftp_cmd_str)) { break; } str_copy(&s_src_str, &s_rhs_str); } } if (!cmd_ok) { vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT")) { vsf_cmdio_write(p_sess, FTP_GOODBYE, "Goodbye."); vsf_sysutil_exit(0); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PWD") || str_equal_text(&p_sess->ftp_cmd_str, "XPWD")) { handle_pwd(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "CWD") || str_equal_text(&p_sess->ftp_cmd_str, "XCWD")) { handle_cwd(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "CDUP") || str_equal_text(&p_sess->ftp_cmd_str, "XCUP")) { handle_cdup(p_sess); } else if (tunable_pasv_enable && !p_sess->epsv_all && (str_equal_text(&p_sess->ftp_cmd_str, "PASV") || str_equal_text(&p_sess->ftp_cmd_str, "P@SW"))) { handle_pasv(p_sess, 0); } else if (tunable_pasv_enable && str_equal_text(&p_sess->ftp_cmd_str, "EPSV")) { handle_pasv(p_sess, 1); } else if (tunable_download_enable && str_equal_text(&p_sess->ftp_cmd_str, "RETR")) { handle_retr(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "NOOP")) { vsf_cmdio_write(p_sess, FTP_NOOPOK, "NOOP ok."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SYST")) { vsf_cmdio_write(p_sess, FTP_SYSTOK, "UNIX Type: L8"); } else if (str_equal_text(&p_sess->ftp_cmd_str, "HELP")) { handle_help(p_sess); } else if (tunable_dirlist_enable && str_equal_text(&p_sess->ftp_cmd_str, "LIST")) { handle_list(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "TYPE")) { handle_type(p_sess); } else if (tunable_port_enable && !p_sess->epsv_all && str_equal_text(&p_sess->ftp_cmd_str, "PORT")) { handle_port(p_sess); } else if (tunable_write_enable && (tunable_anon_upload_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "STOR")) { handle_stor(p_sess); } else if (tunable_write_enable && (tunable_anon_mkdir_write_enable || !p_sess->is_anonymous) && (str_equal_text(&p_sess->ftp_cmd_str, "MKD") || str_equal_text(&p_sess->ftp_cmd_str, "XMKD"))) { handle_mkd(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && (str_equal_text(&p_sess->ftp_cmd_str, "RMD") || str_equal_text(&p_sess->ftp_cmd_str, "XRMD"))) { handle_rmd(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "DELE")) { handle_dele(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "REST")) { handle_rest(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "RNFR")) { handle_rnfr(p_sess); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "RNTO")) { handle_rnto(p_sess); } else if (tunable_dirlist_enable && str_equal_text(&p_sess->ftp_cmd_str, "NLST")) { handle_nlst(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SIZE")) { handle_size(p_sess); } else if (!p_sess->is_anonymous && str_equal_text(&p_sess->ftp_cmd_str, "SITE")) { handle_site(p_sess); } /* Note - the weird ABOR string is checking for an async ABOR arriving * without a SIGURG condition. */ else if (str_equal_text(&p_sess->ftp_cmd_str, "ABOR") || str_equal_text(&p_sess->ftp_cmd_str, "\377\364\377\362ABOR")) { vsf_cmdio_write(p_sess, FTP_ABOR_NOCONN, "No transfer to ABOR."); } else if (tunable_write_enable && (tunable_anon_other_write_enable || !p_sess->is_anonymous) && str_equal_text(&p_sess->ftp_cmd_str, "APPE")) { handle_appe(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "MDTM")) { handle_mdtm(p_sess); } else if (tunable_port_enable && str_equal_text(&p_sess->ftp_cmd_str, "EPRT")) { handle_eprt(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "STRU")) { str_upper(&p_sess->ftp_arg_str); if (str_equal_text(&p_sess->ftp_arg_str, "F")) { vsf_cmdio_write(p_sess, FTP_STRUOK, "Structure set to F."); } else { vsf_cmdio_write(p_sess, FTP_BADSTRU, "Bad STRU command."); } } else if (str_equal_text(&p_sess->ftp_cmd_str, "MODE")) { str_upper(&p_sess->ftp_arg_str); if (str_equal_text(&p_sess->ftp_arg_str, "S")) { vsf_cmdio_write(p_sess, FTP_MODEOK, "Mode set to S."); } else { vsf_cmdio_write(p_sess, FTP_BADMODE, "Bad MODE command."); } } else if (str_equal_text(&p_sess->ftp_cmd_str, "STOU")) { handle_stou(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "ALLO")) { vsf_cmdio_write(p_sess, FTP_ALLOOK, "ALLO command ignored."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "REIN")) { vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "REIN not implemented."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "ACCT")) { vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "ACCT not implemented."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "SMNT")) { vsf_cmdio_write(p_sess, FTP_COMMANDNOTIMPL, "SMNT not implemented."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "FEAT")) { vsf_cmdio_write_hyphen(p_sess, FTP_FEAT, "Features:"); vsf_cmdio_write_raw(p_sess, " MDTM\r\n"); vsf_cmdio_write_raw(p_sess, " REST STREAM\r\n"); vsf_cmdio_write_raw(p_sess, " SIZE\r\n"); vsf_cmdio_write(p_sess, FTP_FEAT, "End"); } else if (str_equal_text(&p_sess->ftp_cmd_str, "OPTS")) { vsf_cmdio_write(p_sess, FTP_BADOPTS, "Option not understood."); } else if (str_equal_text(&p_sess->ftp_cmd_str, "STAT") && str_isempty(&p_sess->ftp_arg_str)) { handle_stat(p_sess); } else if (tunable_dirlist_enable && str_equal_text(&p_sess->ftp_cmd_str, "STAT")) { handle_stat_file(p_sess); } else if (str_equal_text(&p_sess->ftp_cmd_str, "PASV") || str_equal_text(&p_sess->ftp_cmd_str, "PORT") || str_equal_text(&p_sess->ftp_cmd_str, "STOR") || str_equal_text(&p_sess->ftp_cmd_str, "MKD") || str_equal_text(&p_sess->ftp_cmd_str, "XMKD") || str_equal_text(&p_sess->ftp_cmd_str, "RMD") || str_equal_text(&p_sess->ftp_cmd_str, "XRMD") || str_equal_text(&p_sess->ftp_cmd_str, "DELE") || str_equal_text(&p_sess->ftp_cmd_str, "RNFR") || str_equal_text(&p_sess->ftp_cmd_str, "RNTO") || str_equal_text(&p_sess->ftp_cmd_str, "SITE") || str_equal_text(&p_sess->ftp_cmd_str, "APPE") || str_equal_text(&p_sess->ftp_cmd_str, "EPSV") || str_equal_text(&p_sess->ftp_cmd_str, "EPRT") || str_equal_text(&p_sess->ftp_cmd_str, "RETR") || str_equal_text(&p_sess->ftp_cmd_str, "LIST") || str_equal_text(&p_sess->ftp_cmd_str, "NLST") || str_equal_text(&p_sess->ftp_cmd_str, "STOU") || str_equal_text(&p_sess->ftp_cmd_str, "ALLO") || str_equal_text(&p_sess->ftp_cmd_str, "REIN") || str_equal_text(&p_sess->ftp_cmd_str, "ACCT") || str_equal_text(&p_sess->ftp_cmd_str, "SMNT") || str_equal_text(&p_sess->ftp_cmd_str, "FEAT") || str_equal_text(&p_sess->ftp_cmd_str, "OPTS") || str_equal_text(&p_sess->ftp_cmd_str, "STAT")) { vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied."); } else { vsf_cmdio_write(p_sess, FTP_BADCMD, "Unknown command."); } } }
static void *worker_thread(void *data) { struct submit_worker *sw = data; struct workqueue *wq = sw->wq; struct thread_data *td = &sw->td; unsigned int eflags = 0, ret; FLIST_HEAD(local_list); ret = init_submit_worker(sw); pthread_mutex_lock(&sw->lock); sw->flags |= SW_F_RUNNING; if (ret) sw->flags |= SW_F_ERROR; pthread_mutex_unlock(&sw->lock); pthread_mutex_lock(&wq->flush_lock); pthread_cond_signal(&wq->flush_cond); pthread_mutex_unlock(&wq->flush_lock); if (sw->flags & SW_F_ERROR) goto done; while (1) { pthread_mutex_lock(&sw->lock); if (flist_empty(&sw->work_list)) { if (sw->flags & SW_F_EXIT) { pthread_mutex_unlock(&sw->lock); break; } if (td->io_u_queued || td->cur_depth || td->io_u_in_flight) { pthread_mutex_unlock(&sw->lock); io_u_quiesce(td); pthread_mutex_lock(&sw->lock); } /* * We dropped and reaquired the lock, check * state again. */ if (!flist_empty(&sw->work_list)) goto handle_work; if (sw->flags & SW_F_EXIT) { pthread_mutex_unlock(&sw->lock); break; } else if (!(sw->flags & SW_F_IDLE)) { sw->flags |= SW_F_IDLE; wq->next_free_worker = sw->index; if (wq->wake_idle) pthread_cond_signal(&wq->flush_cond); } update_accounting(sw); pthread_cond_wait(&sw->cond, &sw->lock); } else { handle_work: flist_splice_init(&sw->work_list, &local_list); } pthread_mutex_unlock(&sw->lock); handle_list(sw, &local_list); } update_accounting(sw); done: pthread_mutex_lock(&sw->lock); sw->flags |= (SW_F_EXITED | eflags); pthread_mutex_unlock(&sw->lock); return NULL; }
static apr_status_t ftp_protocol_loop(struct lfd_sess * sess) { apr_status_t rc = APR_SUCCESS; int rnfrto; // "rename from" and "rename to" should go togheter char * temp_name; temp_name = NULL; rnfrto = 0; while(APR_SUCCESS == rc) { apr_pool_clear(sess->loop_pool); rc = lfd_cmdio_get_cmd_and_arg(sess, &sess->ftp_cmd_str, &sess->ftp_arg_str); if(APR_SUCCESS != rc) return rc; // special case if(lfd_cmdio_cmd_equals(sess, "RNTO")) { if(rnfrto) { rnfrto = 0; rc = handle_rnto(sess, temp_name); } else rc = handle_bad_rnto(sess); continue; } // here we treat all the other cases if(rnfrto){ rnfrto = 0; rc = handle_bad_rnto(sess); continue; } if(lfd_cmdio_cmd_equals(sess, "PASV")) { rc = handle_pasv(sess); } else if(lfd_cmdio_cmd_equals(sess, "SYST")) { rc = handle_syst(sess); } else if(lfd_cmdio_cmd_equals(sess, "USER")) { rc = handle_user(sess); } else if(lfd_cmdio_cmd_equals(sess, "PASS")) { rc = handle_pass(sess); } else if(lfd_cmdio_cmd_equals(sess, "QUIT")) { rc = handle_quit(sess); return rc; } else if(lfd_cmdio_cmd_equals(sess, "ABOR")) { rc = handle_abort(sess); } else if(lfd_cmdio_cmd_equals(sess, "PORT")) { rc = handle_port(sess); } else if(lfd_cmdio_cmd_equals(sess, "RMD")) { rc = handle_dir_remove(sess); } else if(lfd_cmdio_cmd_equals(sess, "MKD")) { rc = handle_dir_create(sess); } else if(lfd_cmdio_cmd_equals(sess, "PWD")) { rc = handle_pwd(sess); } else if(lfd_cmdio_cmd_equals(sess, "CWD")) { rc = handle_cwd(sess); } else if(lfd_cmdio_cmd_equals(sess, "CDUP")) { rc = handle_cdup(sess); } else if(lfd_cmdio_cmd_equals(sess, "RNFR")) { rc = handle_rnfr(sess, &temp_name); if(APR_SUCCESS == rc && NULL != temp_name) rnfrto = 1; } else if(lfd_cmdio_cmd_equals(sess, "TYPE")) { rc = handle_type(sess); } else if(lfd_cmdio_cmd_equals(sess, "RETR")) { rc = handle_retr(sess); } else if(lfd_cmdio_cmd_equals(sess, "STOR")) { rc = handle_stor(sess); } else if(lfd_cmdio_cmd_equals(sess, "DELE")) { rc = handle_dele(sess); } else if(lfd_cmdio_cmd_equals(sess, "STOU")) { rc = handle_stou(sess); } else if(lfd_cmdio_cmd_equals(sess, "LIST")) { rc = handle_list(sess); } else if(lfd_cmdio_cmd_equals(sess, "FEAT")) { rc = handle_feat(sess); } else if(lfd_cmdio_cmd_equals(sess, "APPE")) { rc = handle_appe(sess); } else if(lfd_cmdio_cmd_equals(sess, "SITE")) { rc = handle_site(sess); } else if(lfd_cmdio_cmd_equals(sess, "ALLO")) { rc = lfd_cmdio_write(sess, FTP_ALLOOK, "ALLO command ignored."); } else if(lfd_cmdio_cmd_equals(sess, "REIN")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "REIN not implemented."); } else if(lfd_cmdio_cmd_equals(sess, "ACCT")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "ACCT not implemented."); } else if(lfd_cmdio_cmd_equals(sess, "SMNT")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "SMNT not implemented."); } else //default { printf("The cmd [%s] has no installed handler! \n", sess->ftp_cmd_str); if(NULL != sess->ftp_arg_str) printf("The cmd args were [%s] \n", sess->ftp_arg_str); lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "Command not implemented."); } } return rc; }
static void *worker_thread(void *data) { struct submit_worker *sw = data; struct workqueue *wq = sw->wq; unsigned int eflags = 0, ret = 0; FLIST_HEAD(local_list); sk_out_assign(sw->sk_out); if (wq->ops.nice) { if (nice(wq->ops.nice) < 0) { log_err("workqueue: nice %s\n", strerror(errno)); ret = 1; } } if (!ret) ret = workqueue_init_worker(sw); pthread_mutex_lock(&sw->lock); sw->flags |= SW_F_RUNNING; if (ret) sw->flags |= SW_F_ERROR; pthread_mutex_unlock(&sw->lock); pthread_mutex_lock(&wq->flush_lock); pthread_cond_signal(&wq->flush_cond); pthread_mutex_unlock(&wq->flush_lock); if (sw->flags & SW_F_ERROR) goto done; while (1) { pthread_mutex_lock(&sw->lock); if (flist_empty(&sw->work_list)) { if (sw->flags & SW_F_EXIT) { pthread_mutex_unlock(&sw->lock); break; } if (workqueue_pre_sleep_check(sw)) { pthread_mutex_unlock(&sw->lock); workqueue_pre_sleep(sw); pthread_mutex_lock(&sw->lock); } /* * We dropped and reaquired the lock, check * state again. */ if (!flist_empty(&sw->work_list)) goto handle_work; if (sw->flags & SW_F_EXIT) { pthread_mutex_unlock(&sw->lock); break; } else if (!(sw->flags & SW_F_IDLE)) { sw->flags |= SW_F_IDLE; wq->next_free_worker = sw->index; if (wq->wake_idle) pthread_cond_signal(&wq->flush_cond); } if (wq->ops.update_acct_fn) wq->ops.update_acct_fn(sw); pthread_cond_wait(&sw->cond, &sw->lock); } else { handle_work: flist_splice_init(&sw->work_list, &local_list); } pthread_mutex_unlock(&sw->lock); handle_list(sw, &local_list); } if (wq->ops.update_acct_fn) wq->ops.update_acct_fn(sw); done: pthread_mutex_lock(&sw->lock); sw->flags |= (SW_F_EXITED | eflags); pthread_mutex_unlock(&sw->lock); sk_out_drop(); return NULL; }