fixed flags conflicts

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-FileSharingPermissions@5758 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-11-02 13:52:29 +00:00
parent dc82cee700
commit e753f22909
43 changed files with 383 additions and 386 deletions

View file

@ -65,24 +65,27 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000;
// Flags used when requesting info about transfers, mostly to filter out the result.
//
const TransferInfoFlags RS_FILE_HINTS_CACHE = 0x00000001;
const TransferInfoFlags RS_FILE_HINTS_EXTRA = 0x00000002;
const TransferInfoFlags RS_FILE_HINTS_LOCAL = 0x00000004;
const TransferInfoFlags RS_FILE_HINTS_REMOTE = 0x00000008;
const TransferInfoFlags RS_FILE_HINTS_DOWNLOAD = 0x00000010;
const TransferInfoFlags RS_FILE_HINTS_UPLOAD = 0x00000020;
const TransferInfoFlags RS_FILE_HINTS_NETWORK_WIDE = 0x00000080;// anonymously shared over network
const TransferInfoFlags RS_FILE_HINTS_BROWSABLE = 0x00000100;// browsable by friends
const TransferInfoFlags RS_FILE_HINTS_PERMISSION_MASK = 0x00000180;// OR of the last two flags. Used to filter out.
const FileSearchFlags RS_FILE_HINTS_CACHE ( 0x00000001 );
const FileSearchFlags RS_FILE_HINTS_EXTRA ( 0x00000002 );
const FileSearchFlags RS_FILE_HINTS_LOCAL ( 0x00000004 );
const FileSearchFlags RS_FILE_HINTS_REMOTE ( 0x00000008 );
const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 );
const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 );
const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 );
const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network
const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends
const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out.
// Flags used when requesting a transfer
//
const TransferInfoFlags RS_FILE_HINTS_ANONYMOUS_ROUTING = 0x00000040; // Use to ask turtle router to download the file.
const TransferInfoFlags RS_FILE_HINTS_ASSUME_AVAILABILITY = 0x00000200; // Assume full source availability. Used for cache files.
const TransferInfoFlags RS_FILE_HINTS_MEDIA = 0x00001000;
const TransferInfoFlags RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly.
const TransferInfoFlags RS_FILE_HINTS_SPEC_ONLY = 0x01000000;
const TransferInfoFlags RS_FILE_HINTS_NO_SEARCH = 0x02000000; // disable searching for potential direct sources.
const TransferRequestFlags RS_FILE_REQ_ANONYMOUS_ROUTING ( 0x00000040 ); // Use to ask turtle router to download the file.
const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files.
const TransferRequestFlags RS_FILE_REQ_CACHE ( 0x00000400 ); // Assume full source availability. Used for cache files.
const TransferRequestFlags RS_FILE_REQ_EXTRA ( 0x00000800 );
const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 );
const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly.
const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // disable searching for potential direct sources.
// const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS
// | RS_FILE_HINTS_NETWORK_WIDE_GROUPS | RS_FILE_HINTS_BROWSABLE_GROUPS ;
@ -95,7 +98,7 @@ struct SharedDirInfo
{
std::string filename ;
std::string virtualname ;
uint32_t shareflags ; // RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE
FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ...
std::list<std::string> parent_groups ;
};
@ -116,7 +119,7 @@ class RsFiles
virtual bool alreadyHaveFile(const std::string& hash, FileInfo &info) = 0;
/// Returns false is we already have the file. Otherwise, initiates the dl and returns true.
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferInfoFlags flags, const std::list<std::string>& srcIds) = 0;
virtual bool FileRequest(const std::string& fname, const std::string& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list<std::string>& srcIds) = 0;
virtual bool FileCancel(const std::string& hash) = 0;
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
@ -144,7 +147,7 @@ class RsFiles
***/
virtual bool FileDownloads(std::list<std::string> &hashs) = 0;
virtual bool FileUploads(std::list<std::string> &hashs) = 0;
virtual bool FileDetails(const std::string &hash, TransferInfoFlags hintflags, FileInfo &info) = 0;
virtual bool FileDetails(const std::string &hash, FileSearchFlags hintflags, FileInfo &info) = 0;
/// Gives chunk details about the downloaded file with given hash.
virtual bool FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ;
@ -155,9 +158,9 @@ class RsFiles
/***
* Extra List Access
***/
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferInfoFlags flags) = 0;
virtual bool ExtraFileRemove(std::string hash, TransferInfoFlags flags) = 0;
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferInfoFlags flags) = 0;
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, TransferRequestFlags flags) = 0;
virtual bool ExtraFileRemove(std::string hash, TransferRequestFlags flags) = 0;
virtual bool ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) = 0;
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
std::string destpath) = 0;
@ -168,14 +171,13 @@ class RsFiles
* Directory Listing / Search Interface
*/
virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) = 0;
virtual uint32_t getType(void *ref,FileSearchFlags flags) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, FileStorageFlags flags) = 0;
virtual uint32_t getType(void *ref,TransferInfoFlags flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags,const std::string& peer_id) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const std::string& peer_id) = 0;
/***
* Utility Functions.

View file

@ -1,29 +1,64 @@
#pragma once
#include <stdint.h>
// This class provides a representation for flags that can be combined with bitwise
// operations. However, because the class is templated with an id, it's not possible to
// mixup flags belonging to different classes. This avoids many bugs due to confusion of flags types
// that occur when all flags are uint32_t values.
//
// To use this class, define an ID that is different than other flags classes, and do a typedef:
//
// #define TRANSFER_INFO_FLAGS_TAG 0x8133ea
// typedef t_RsFlags32<TRANSFER_INFO_FLAGS_TAG> TransferInfoFlags ;
//
// Implementation details:
// - we cannot have at the same time a implicit contructor from uint32_t and a bool operator, otherwise c++
// mixes up operators and transforms flags into booleans before combining them further.
//
// So I decided to have:
// - an explicit constructor from uint32_t
// - an implicit bool operator, that allows test like if(flags & FLAGS_VALUE)
//
template<int n> class t_RsFlags32
{
public:
t_RsFlags32() {}
inline t_RsFlags32() { _bits=0; }
inline explicit t_RsFlags32(uint32_t N) : _bits(N) {} // allows initialization from a set of uint32_t
t_RsFlags32(uint32_t N) : _bits(N) {}
operator uint32_t() const { return _bits ; }
inline t_RsFlags32<n> operator| (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits | f._bits) ; }
inline t_RsFlags32<n> operator^ (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits ^ f._bits) ; }
t_RsFlags32<n> operator| (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits | f._bits) ; }
t_RsFlags32<n> operator^ (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits ^ f._bits) ; }
t_RsFlags32<n> operator& (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits & f._bits) ; }
inline bool operator!=(const t_RsFlags32<n>& f) const { return _bits != f._bits ; }
inline bool operator& (const t_RsFlags32<n>& f) const { return (_bits & f._bits)>0 ; }
t_RsFlags32<n> operator|=(const t_RsFlags32<n>& f) { _bits |= f._bits ; return *this ;}
t_RsFlags32<n> operator^=(const t_RsFlags32<n>& f) { _bits ^= f._bits ; return *this ;}
t_RsFlags32<n> operator&=(const t_RsFlags32<n>& f) { _bits &= f._bits ; return *this ;}
inline t_RsFlags32<n> operator|=(const t_RsFlags32<n>& f) { _bits |= f._bits ; return *this ;}
inline t_RsFlags32<n> operator^=(const t_RsFlags32<n>& f) { _bits ^= f._bits ; return *this ;}
inline t_RsFlags32<n> operator&=(const t_RsFlags32<n>& f) { _bits &= f._bits ; return *this ;}
t_RsFlags32<n> operator~() const { return t_RsFlags32<n>(~_bits) ; }
inline t_RsFlags32<n> operator~() const { return t_RsFlags32<n>(~_bits) ; }
//inline explicit operator bool() const { return _bits>0; }
inline uint32_t toUInt32() const { return _bits ; }
void clear() { _bits = 0 ; }
friend std::ostream& operator<<(std::ostream& o,const t_RsFlags32<n>& f) // friendly print with 0 and I
{
for(int i=31;i>=0;--i) { o << ( (f._bits&(1<<i))?"I":"0") ; if(i%8==0) o << " " ; }
return o ;
}
private:
uint32_t _bits ;
};
#define TRANSFER_INFO_FLAGS_TAG 0x8133ea
#define FILE_STORAGE_FLAGS_TAG 0x184738
#define FLAGS_TAG_FILE_SEARCH 0xf29ba5
#define FLAGS_TAG_PERMISSION 0x8133ea
#define FLAGS_TAG_TRANSFER_REQS 0x4228af
#define FLAGS_TAG_FILE_STORAGE 0x184738
typedef t_RsFlags32<TRANSFER_INFO_FLAGS_TAG> TransferInfoFlags ;
typedef t_RsFlags32<FILE_STORAGE_FLAGS_TAG > FileStorageFlags ; // this makes it a uint32_t class incompatible with other flag class
typedef t_RsFlags32<FLAGS_TAG_PERMISSION> FilePermissionFlags ;
typedef t_RsFlags32<FLAGS_TAG_TRANSFER_REQS> TransferRequestFlags ;
typedef t_RsFlags32<FLAGS_TAG_FILE_STORAGE > FileStorageFlags ; // this makes it a uint32_t class incompatible with other flag class
typedef t_RsFlags32<FLAGS_TAG_FILE_SEARCH > FileSearchFlags ; // this makes it a uint32_t class incompatible with other flag class

View file

@ -307,7 +307,7 @@ class RsPeers
// ... computes the sharing file permission hint flags set for this peer, that is a combination of
// RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE.
//
virtual TransferInfoFlags computePeerPermissionFlags(const std::string& peer_id,FileStorageFlags file_sharing_flags,const std::list<std::string>& file_parent_groups) = 0;
virtual FileSearchFlags computePeerPermissionFlags(const std::string& peer_id,FileStorageFlags file_sharing_flags,const std::list<std::string>& file_parent_groups) = 0;
};

View file

@ -202,19 +202,19 @@ class SearchRequest
* (TODO)
*/
const FileStorageFlags DIR_FLAGS_PARENT = 0x0001;
const FileStorageFlags DIR_FLAGS_DETAILS = 0x0002;
const FileStorageFlags DIR_FLAGS_CHILDREN = 0x0004;
const FileStorageFlags DIR_FLAGS_PARENT ( 0x0001 );
const FileStorageFlags DIR_FLAGS_DETAILS ( 0x0002 ); // apparently unused
const FileStorageFlags DIR_FLAGS_CHILDREN ( 0x0004 ); // apparently unused
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_OTHERS = 0x0080; // Flags for directory sharing permissions. The last
const FileStorageFlags DIR_FLAGS_BROWSABLE_OTHERS = 0x0100; // one should be the OR of the all four flags.
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_GROUPS = 0x0200;
const FileStorageFlags DIR_FLAGS_BROWSABLE_GROUPS = 0x0400;
const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK = DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_OTHERS
| DIR_FLAGS_NETWORK_WIDE_GROUPS | DIR_FLAGS_BROWSABLE_GROUPS ;
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_OTHERS ( 0x0080 ); // Flags for directory sharing permissions. The last
const FileStorageFlags DIR_FLAGS_BROWSABLE_OTHERS ( 0x0100 ); // one should be the OR of the all four flags.
const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_GROUPS ( 0x0200 );
const FileStorageFlags DIR_FLAGS_BROWSABLE_GROUPS ( 0x0400 );
const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_OTHERS
| DIR_FLAGS_NETWORK_WIDE_GROUPS | DIR_FLAGS_BROWSABLE_GROUPS );
const FileStorageFlags DIR_FLAGS_LOCAL = 0x1000;
const FileStorageFlags DIR_FLAGS_REMOTE = 0x2000;
const FileStorageFlags DIR_FLAGS_LOCAL ( 0x1000 );
const FileStorageFlags DIR_FLAGS_REMOTE ( 0x2000 );
class FileInfo
{
@ -224,8 +224,8 @@ class FileInfo
FileInfo() : mId(0) { return; }
RsCertId id; /* key for matching everything */
FileStorageFlags storage_permission_flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file.
TransferInfoFlags transfer_info_flags ; // various flags from RS_FILE_HINTS_*
FileStorageFlags storage_permission_flags; // Combination of the four RS_DIR_FLAGS_*. Updated when the file is a local stored file.
TransferRequestFlags transfer_info_flags ; // various flags from RS_FILE_HINTS_*
/* allow this to be tweaked by the GUI Model */
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
@ -327,7 +327,6 @@ class FileChunksInfo
uint64_t file_size ; // real size of the file
uint32_t chunk_size ; // size of chunks
uint32_t flags ;
uint32_t strategy ;
// dl state of chunks. Only the last chunk may have size < chunk_size