}
void
-Ftp::Client::failed(err_type error, int xerrno)
+Ftp::Client::failed(err_type error, int xerrno, ErrorState *err)
{
debugs(9, 3, "entry-null=" << (entry?entry->isEmpty():0) << ", entry=" << entry);
const char *command, *reply;
- const Http::StatusCode httpStatus = failedHttpStatus(error);
- ErrorState *const ftperr = new ErrorState(error, httpStatus, fwd->request);
+ ErrorState *ftperr;
+
+ if (err) {
+ debugs(9, 6, "error=" << err->type << ", code=" << xerrno <<
+ ", status=" << err->httpStatus);
+ error = err->type;
+ ftperr = err;
+ } else {
+ Http::StatusCode httpStatus = failedHttpStatus(error);
+ ftperr = new ErrorState(error, httpStatus, fwd->request);
+ }
+
ftperr->xerrno = xerrno;
ftperr->ftp.server_msg = ctrl.message;
if (reply)
ftperr->ftp.reply = xstrdup(reply);
- fwd->request->detailError(error, xerrno);
- fwd->fail(ftperr);
-
- closeServer(); // we failed, so no serverComplete()
+ if (!err) {
+ fwd->request->detailError(error, xerrno);
+ fwd->fail(ftperr);
+ closeServer(); // we failed, so no serverComplete()
+ }
}
Http::StatusCode
Ftp::Gateway::loginFailed()
{
ErrorState *err = NULL;
- const char *command, *reply;
if ((state == SENT_USER || state == SENT_PASS) && ctrl.replycode >= 400) {
if (ctrl.replycode == 421 || ctrl.replycode == 426) {
}
}
- // any other problems are general falures.
if (!err) {
ftpFail(this);
return;
}
- err->ftp.server_msg = ctrl.message;
-
- ctrl.message = NULL;
-
- if (old_request)
- command = old_request;
- else
- command = ctrl.last_command;
-
- if (command && strncmp(command, "PASS", 4) == 0)
- command = "PASS <yourpassword>";
-
- if (old_reply)
- reply = old_reply;
- else
- reply = ctrl.last_reply;
-
- if (command)
- err->ftp.request = xstrdup(command);
-
- if (reply)
- err->ftp.reply = xstrdup(reply);
+ failed(ERR_NONE, ctrl.replycode, err);
+ // any other problems are general falures.
HttpReply *newrep = err->BuildHttpReply();
delete err;
ftpFail(Ftp::Gateway *ftpState)
{
const bool slashHack = ftpState->request->url.path().caseCmp("/%2f", 4)==0;
- debugs(9, 6, "flags(" <<
+ int code = ftpState->ctrl.replycode;
+ err_type error_code = ERR_NONE;
+
+ debugs(9, 6, "state " << ftpState->state <<
+ " reply code " << code << "flags(" <<
(ftpState->flags.isdir?"IS_DIR,":"") <<
(ftpState->flags.try_slash_hack?"TRY_SLASH_HACK":"") << "), " <<
"mdtm=" << ftpState->mdtm << ", size=" << ftpState->theSize <<
}
}
- ftpState->failed(ERR_NONE, 0);
- /* failed() closes ctrl.conn and frees this */
+ Http::StatusCode sc = ftpState->failedHttpStatus(error_code);
+ ErrorState *ftperr = new ErrorState(error_code, sc, ftpState->fwd->request);
+ ftpState->failed(error_code, code, ftperr);
+ ftperr->detailError(code);
+ HttpReply *newrep = ftperr->BuildHttpReply();
+ delete ftperr;
+
+ ftpState->entry->replaceHttpReply(newrep);
+ ftpSendQuit(ftpState);
}
Http::StatusCode