Skip to content

Commit

Permalink
feat(client): return new 'file_list_reply' from get_file_list() method
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskovalchuk committed Sep 22, 2023
1 parent a6ca418 commit 3a135c1
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(sources
include/ftp/stream/ostream_adapter.hpp
include/ftp/stream/output_stream.hpp
include/ftp/client.hpp
include/ftp/file_list_reply.hpp
include/ftp/file_size_reply.hpp
include/ftp/ftp.hpp
include/ftp/ftp_exception.hpp
Expand All @@ -41,6 +42,7 @@ set(sources
src/client.cpp
src/control_connection.cpp
src/data_connection.cpp
src/file_list_reply.cpp
src/file_size_reply.cpp
src/istream_adapter.cpp
src/ostream_adapter.cpp
Expand Down
3 changes: 2 additions & 1 deletion include/ftp/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define LIBFTP_CLIENT_HPP

#include <ftp/observer.hpp>
#include <ftp/file_list_reply.hpp>
#include <ftp/file_size_reply.hpp>
#include <ftp/replies.hpp>
#include <ftp/reply.hpp>
Expand Down Expand Up @@ -83,7 +84,7 @@ class client

replies append_file(input_stream && src, std::string_view path, transfer_callback * transfer_cb = nullptr);

replies get_file_list(const std::optional<std::string_view> & path = std::nullopt, bool only_names = false);
file_list_reply get_file_list(const std::optional<std::string_view> & path = std::nullopt, bool only_names = false);

replies rename(std::string_view from_path, std::string_view to_path);

Expand Down
48 changes: 48 additions & 0 deletions include/ftp/file_list_reply.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* MIT License
*
* Copyright (c) 2023 Denis Kovalchuk
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef LIBFTP_FILE_LIST_REPLY_HPP
#define LIBFTP_FILE_LIST_REPLY_HPP

#include <ftp/replies.hpp>
#include <string>

namespace ftp
{

class file_list_reply : public replies
{
public:
file_list_reply();

file_list_reply(const replies & replies, const std::string & file_list);

[[nodiscard]] const std::string & get_file_list() const;

private:
std::string file_list_;
};

} // namespace ftp
#endif //LIBFTP_FILE_LIST_REPLY_HPP
12 changes: 8 additions & 4 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ replies client::append_file(input_stream && src, std::string_view path, transfer
return process_upload("APPE", src, path, transfer_cb);
}

replies client::get_file_list(const std::optional<std::string_view> & path, bool only_names)
file_list_reply client::get_file_list(const std::optional<std::string_view> & path, bool only_names)
{
std::string command;

Expand All @@ -168,6 +168,8 @@ replies client::get_file_list(const std::optional<std::string_view> & path, bool
}

replies replies;
std::string file_list;

data_connection_ptr connection = create_data_connection(command, replies);

if (connection)
Expand All @@ -176,13 +178,15 @@ replies client::get_file_list(const std::optional<std::string_view> & path, bool
ostream_adapter adapter(oss);
output_stream_ptr stream = create_output_stream(adapter);
connection->recv(*stream, nullptr);
notify_file_list(oss.str());
connection->close();

file_list = oss.str();
notify_file_list(file_list);

connection->close();
recv(replies);
}

return replies;
return { replies, file_list };
}

replies client::rename(std::string_view from_path, std::string_view to_path)
Expand Down
44 changes: 44 additions & 0 deletions src/file_list_reply.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* MIT License
*
* Copyright (c) 2023 Denis Kovalchuk
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <ftp/file_list_reply.hpp>

namespace ftp
{

file_list_reply::file_list_reply()
: ftp::replies()
{}

file_list_reply::file_list_reply(const replies & replies, const std::string & file_list)
: ftp::replies(replies),
file_list_(file_list)
{}

const std::string & file_list_reply::get_file_list() const
{
return file_list_;
}

} // namespace ftp

0 comments on commit 3a135c1

Please sign in to comment.