MCPcopy Create free account
hub / github.com/apache/httpd / ftp_getrc_msg

Function ftp_getrc_msg

modules/proxy/mod_proxy_ftp.c:381–425  ·  view source on GitHub ↗

* Reads response lines, returns both the ftp status code and * remembers the response message in the supplied buffer */

Source from the content-addressed store, hash-verified

379 * remembers the response message in the supplied buffer
380 */
381static int ftp_getrc_msg(conn_rec *ftp_ctrl, apr_bucket_brigade *bb, char *msgbuf, int msglen)
382{
383 int status;
384 char response[MAX_LINE_LEN];
385 char buff[5];
386 char *mb = msgbuf, *me = &msgbuf[msglen];
387 apr_status_t rv;
388 apr_size_t nread;
389
390 int eos;
391
392 if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos, &nread))) {
393 return -1;
394 }
395/*
396 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, APLOGNO(03233)
397 "<%s", response);
398*/
399 if (nread < 4) {
400 ap_log_error(APLOG_MARK, APLOG_INFO, 0, NULL, APLOGNO(10229) "Malformed FTP response '%s'", response);
401 *mb = '\0';
402 return -1;
403 }
404
405 if (!apr_isdigit(response[0]) || !apr_isdigit(response[1]) ||
406 !apr_isdigit(response[2]) || (response[3] != ' ' && response[3] != '-'))
407 status = 0;
408 else
409 status = 100 * response[0] + 10 * response[1] + response[2] - 111 * '0';
410
411 mb = apr_cpystrn(mb, response + 4, me - mb);
412
413 if (response[3] == '-') { /* multi-line reply "123-foo\nbar\n123 baz" */
414 memcpy(buff, response, 3);
415 buff[3] = ' ';
416 do {
417 if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos, &nread))) {
418 return -1;
419 }
420 mb = apr_cpystrn(mb, response + (' ' == response[0] ? 1 : 4), me - mb);
421 } while (memcmp(response, buff, 4) != 0);
422 }
423
424 return status;
425}
426
427/* this is a filter that turns a raw ASCII directory listing into pretty HTML */
428

Callers 1

proxy_ftp_commandFunction · 0.85

Calls 2

ftp_string_readFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected