static int output_response(request_rec *r, SV *res) { dTHX; AV *res_av; SV **status; SV **headers; AV *headers_av; SV **body; int rc; if (!SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVAV) { server_error(r, "response must be an array reference"); return HTTP_INTERNAL_SERVER_ERROR; } res_av = (AV *) SvRV(res); if (av_len(res_av) != 2) { server_error(r, "response must have 3 elements"); return HTTP_INTERNAL_SERVER_ERROR; } status = av_fetch(res_av, 0, 0); if (!SvOK(*status)) { server_error(r, "response status must be a scalar value"); return HTTP_INTERNAL_SERVER_ERROR; } rc = output_status(r, *status); if (rc != OK) return rc; headers = av_fetch(res_av, 1, 0); if (!SvROK(*headers) || SvTYPE(SvRV(*headers)) != SVt_PVAV) { server_error(r, "response headers must be an array reference"); return HTTP_INTERNAL_SERVER_ERROR; } headers_av = (AV *) SvRV(*headers); if ((av_len(headers_av) + 1) % 2 != 0) { server_error(r, "num of response headers must be even"); return HTTP_INTERNAL_SERVER_ERROR; } rc = output_headers(r, headers_av); if (rc != OK) return rc; body = av_fetch(res_av, 2, 0); if (!SvROK(*body)) { server_error(r, "response body must be a reference"); return HTTP_INTERNAL_SERVER_ERROR; } rc = output_body(r, *body); return rc; }
int mz_sendmail_send_password_mail (const char *command_path, const char *from, const char *recipient, const char *body, unsigned int body_length, const char *boundary, const char *password, int timeout) { pid_t pid; int stdout_pipe[2]; int stderr_pipe[2]; int stdin_pipe[2]; if (pipe(stdout_pipe) < 0 || pipe(stderr_pipe) < 0 || pipe(stdin_pipe) < 0) { return -1; } pid = fork(); if (pid == -1) return -1; if (pid == 0) { close_pipe(stdout_pipe, READ); close_pipe(stderr_pipe, READ); close_pipe(stdin_pipe, WRITE); if (sane_dup2(stdin_pipe[READ], STDIN_FILENO) < 0 || sane_dup2(stdout_pipe[WRITE], STDOUT_FILENO) < 0 || sane_dup2(stderr_pipe[WRITE], STDERR_FILENO) < 0) { } if (stdin_pipe[READ] >= 3) close_pipe(stdin_pipe, READ); if (stdout_pipe[WRITE] >= 3) close_pipe(stdout_pipe, WRITE); if (stderr_pipe[WRITE] >= 3) close_pipe(stderr_pipe, WRITE); execl(command_path, command_path, recipient, (char*)NULL); _exit(-1); } else { int status; close_pipe(stdout_pipe, WRITE); close_pipe(stderr_pipe, WRITE); close_pipe(stdin_pipe, READ); output_headers(stdin_pipe[WRITE], from, recipient, boundary); output_password(stdin_pipe[WRITE], password, boundary); output_body(stdin_pipe[WRITE], body, body_length); while (waitpid(pid, &status, WNOHANG) <= 0); return status; } return 0; }