Expose /rsFiles/requestDirDetails via JSON API

This method is useful to browse own shared directries, or directries
shared by friends whith browseable permission
This commit is contained in:
Gioacchino Mazzurco 2018-10-09 22:58:17 +02:00
parent 2139090f5d
commit c05c376351
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
6 changed files with 89 additions and 29 deletions

View file

@ -26,6 +26,7 @@
#include <string>
#include <functional>
#include <chrono>
#include <cstdint>
#include "rstypes.h"
#include "serialiser/rsserializable.h"
@ -423,13 +424,32 @@ public:
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
virtual bool ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath) = 0;
/**
* @brief Request directory details, subsequent multiple call may be used to
* explore a whole directory tree.
* @jsonapi{development}
* @param[out] details Storage for directory details
* @param[in] handle element handle 0 for root, pass the content of
* DirDetails::child[x].ref after first call to explore deeper, be aware
* that is not a real pointer but an index used internally by RetroShare.
* @param[in] flags file search flags RS_FILE_HINTS_*
* @return false if error occurred, true otherwise
*/
virtual bool requestDirDetails(
DirDetails &details, std::uintptr_t handle = 0,
FileSearchFlags flags = RS_FILE_HINTS_LOCAL ) = 0;
/***
* Directory Listing / Search Interface
*/
/**
* Kept for retrocompatibility, it was originally written for easier
* interaction with Qt. As soon as you can, you should prefer to use the
* version of this methodn which take `std::uintptr_t handle` as paramether.
*/
virtual int RequestDirDetails(
void* handle, DirDetails& details, FileSearchFlags flags ) = 0;
/***
* Directory Listing / Search Interface
*/
virtual int RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) = 0;
virtual bool findChildPointer(void *ref, int row, void *& result, FileSearchFlags flags) =0;
virtual uint32_t getType(void *ref,FileSearchFlags flags) = 0;

View file

@ -23,7 +23,7 @@
template<int n> class t_RsFlags32
{
public:
inline t_RsFlags32() { _bits=0; }
inline t_RsFlags32() : _bits(0) {}
inline explicit t_RsFlags32(uint32_t N) : _bits(N) {} // allows initialization from a set of uint32_t
inline t_RsFlags32<n> operator| (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits | f._bits) ; }

View file

@ -257,21 +257,43 @@ struct FileInfo : RsSerializable
std::ostream &operator<<(std::ostream &out, const FileInfo& info);
class DirStub
/**
* Pointers in this class have no real meaning as pointers, they are used as
* indexes, internally by retroshare.
*/
struct DirStub : RsSerializable
{
public:
DirStub() : type(DIR_TYPE_UNKNOWN), ref(nullptr) {}
uint8_t type;
std::string name;
void *ref;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(type);
RS_SERIAL_PROCESS(name);
std::uintptr_t& handle(reinterpret_cast<std::uintptr_t&>(ref));
RS_SERIAL_PROCESS(handle);
}
};
class DirDetails
/**
* Pointers in this class have no real meaning as pointers, they are used as
* indexes, internally by retroshare.
*/
struct DirDetails : RsSerializable
{
public:
void *parent;
int prow; /* parent row */
DirDetails() : parent(nullptr), prow(0), ref(nullptr),
type(DIR_TYPE_UNKNOWN), count(0), mtime(0), max_mtime(0) {}
void *ref;
void* parent;
int prow; /* parent row */
void* ref;
uint8_t type;
RsPeerId id;
std::string name;
@ -284,6 +306,28 @@ public:
std::vector<DirStub> children;
std::list<RsNodeGroupId> parent_groups; // parent groups for the shared directory
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
std::uintptr_t& parentHandle(reinterpret_cast<std::uintptr_t&>(parent));
RS_SERIAL_PROCESS(parentHandle);
RS_SERIAL_PROCESS(prow);
std::uintptr_t& handle(reinterpret_cast<std::uintptr_t&>(ref));
RS_SERIAL_PROCESS(handle);
RS_SERIAL_PROCESS(type);
RS_SERIAL_PROCESS(id);
RS_SERIAL_PROCESS(name);
RS_SERIAL_PROCESS(hash);
RS_SERIAL_PROCESS(path);
RS_SERIAL_PROCESS(count);
RS_SERIAL_PROCESS(mtime);
RS_SERIAL_PROCESS(flags);
RS_SERIAL_PROCESS(max_mtime);
RS_SERIAL_PROCESS(children);
RS_SERIAL_PROCESS(parent_groups);
}
};
std::ostream &operator<<(std::ostream &out, const DirDetails& details);