From 047bf7e1c6c28210c38307d113b6bc1464cdd083 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 27 Jan 2007 10:05:40 +0100 Subject: [PATCH] ftp: ftp didn't handle filenames with spaces. --- src/protocol/common.c | 8 ++------ src/protocol/ftp/ftp.c | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/protocol/common.c b/src/protocol/common.c index c21dc42ca..0c985ba17 100644 --- a/src/protocol/common.c +++ b/src/protocol/common.c @@ -63,12 +63,8 @@ init_directory_listing(struct string *page, struct uri *uri) && !add_char_to_string(&dirpath, local ? CHAR_DIR_SEP : '/')) goto out_of_memory; - if (local || uri->protocol == PROTOCOL_FSP || uri->protocol == PROTOCOL_GOPHER - || uri->protocol == PROTOCOL_SMB) { - /* A little hack to get readable Gopher names. We should find a - * way to do it more general. */ - decode_uri_string(&dirpath); - } + /* Decode uri for displaying. */ + decode_uri_string(&dirpath); if (!local && !add_char_to_string(&location, '/')) goto out_of_memory; diff --git a/src/protocol/ftp/ftp.c b/src/protocol/ftp/ftp.c index 01e301bc0..ac2917a07 100644 --- a/src/protocol/ftp/ftp.c +++ b/src/protocol/ftp/ftp.c @@ -683,8 +683,15 @@ add_file_cmd_to_str(struct connection *conn) if (!conn->uri->datalen || conn->uri->data[conn->uri->datalen - 1] == '/') { + struct string uri_string; /* Commands to get directory listing. */ + if (!init_string(&uri_string)) { + done_string(&command); + done_string(&ftp_data_command); + abort_connection(conn, S_OUT_OF_MEM); + return NULL; + } ftp->dir = 1; ftp->pending_commands = 4; @@ -695,17 +702,27 @@ add_file_cmd_to_str(struct connection *conn) add_string_to_string(&command, &ftp_data_command); add_to_string(&command, "CWD "); - add_uri_to_string(&command, conn->uri, URI_PATH); + add_uri_to_string(&uri_string, conn->uri, URI_PATH); + decode_uri_string(&uri_string); + add_string_to_string(&command, &uri_string); add_crlf_to_string(&command); add_to_string(&command, "LIST"); add_crlf_to_string(&command); + done_string(&uri_string); conn->from = 0; } else { + struct string uri_string; /* Commands to get a file. */ + if (!init_string(&uri_string)) { + done_string(&command); + done_string(&ftp_data_command); + abort_connection(conn, S_OUT_OF_MEM); + return NULL; + } ftp->dir = 0; ftp->pending_commands = 3; @@ -727,8 +744,11 @@ add_file_cmd_to_str(struct connection *conn) } add_to_string(&command, "RETR "); - add_uri_to_string(&command, conn->uri, URI_PATH); + add_uri_to_string(&uri_string, conn->uri, URI_PATH); + decode_uri_string(&uri_string); + add_string_to_string(&command, &uri_string); add_crlf_to_string(&command); + done_string(&uri_string); } done_string(&ftp_data_command); @@ -1134,7 +1154,7 @@ display_dir_entry(struct cache_entry *cached, off_t *pos, int *tries, } add_to_string(&string, "name.source, ftp_info->name.length); + encode_uri_string(&string, ftp_info->name.source, ftp_info->name.length, 0); if (ftp_info->type == FTP_FILE_DIRECTORY) add_char_to_string(&string, '/'); add_to_string(&string, "\">");