diff --git a/headers/os/storage/FindDirectory.h b/headers/os/storage/FindDirectory.h index 4b74cfa9c7..29b64cd259 100644 --- a/headers/os/storage/FindDirectory.h +++ b/headers/os/storage/FindDirectory.h @@ -20,7 +20,7 @@ typedef enum { B_SYSTEM_BOOT_DIRECTORY, B_SYSTEM_FONTS_DIRECTORY, B_SYSTEM_LIB_DIRECTORY, - B_SYSTEM_SERVERS_DIRECTORY, + B_SYSTEM_SERVERS_DIRECTORY, B_SYSTEM_APPS_DIRECTORY, B_SYSTEM_BIN_DIRECTORY, B_SYSTEM_DOCUMENTATION_DIRECTORY = 1010, @@ -86,7 +86,7 @@ typedef enum { B_USER_NONPACKAGED_DEVELOP_DIRECTORY, B_USER_DEVELOP_DIRECTORY, B_USER_DOCUMENTATION_DIRECTORY, - B_USER_SERVERS_DIRECTORY, + B_USER_SERVERS_DIRECTORY, B_USER_APPS_DIRECTORY, B_USER_BIN_DIRECTORY, B_USER_PREFERENCES_DIRECTORY, @@ -108,7 +108,7 @@ typedef enum { B_BEOS_BOOT_DIRECTORY, B_BEOS_FONTS_DIRECTORY, B_BEOS_LIB_DIRECTORY, - B_BEOS_SERVERS_DIRECTORY, + B_BEOS_SERVERS_DIRECTORY, B_BEOS_APPS_DIRECTORY, B_BEOS_BIN_DIRECTORY, B_BEOS_ETC_DIRECTORY, diff --git a/headers/os/storage/MimeType.h b/headers/os/storage/MimeType.h index f82548c394..ccd98fd26c 100644 --- a/headers/os/storage/MimeType.h +++ b/headers/os/storage/MimeType.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2006 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _MIME_TYPE_H @@ -14,6 +14,7 @@ #include #include + class BBitmap; class BResources; class BAppFileInfo; @@ -32,12 +33,12 @@ enum app_verb { B_OPEN }; -extern const char *B_APP_MIME_TYPE; // platform dependent -extern const char *B_PEF_APP_MIME_TYPE; // "application/x-be-executable" -extern const char *B_PE_APP_MIME_TYPE; // "application/x-vnd.be-peexecutable" -extern const char *B_ELF_APP_MIME_TYPE; // "application/x-vnd.be-elfexecutable" -extern const char *B_RESOURCE_MIME_TYPE;// "application/x-be-resource" -extern const char *B_FILE_MIME_TYPE; // "application/octet-stream" +extern const char* B_APP_MIME_TYPE; // platform dependent +extern const char* B_PEF_APP_MIME_TYPE; // "application/x-be-executable" +extern const char* B_PE_APP_MIME_TYPE; // "application/x-vnd.be-peexecutable" +extern const char* B_ELF_APP_MIME_TYPE; // "application/x-vnd.be-elfexecutable" +extern const char* B_RESOURCE_MIME_TYPE;// "application/x-be-resource" +extern const char* B_FILE_MIME_TYPE; // "application/octet-stream" /* ------------------------------------------------------------- */ @@ -71,113 +72,114 @@ enum { }; class BMimeType { - public: - BMimeType(); - BMimeType(const char *mimeType); - virtual ~BMimeType(); +public: + BMimeType(); + BMimeType(const char* mimeType); + virtual ~BMimeType(); - status_t SetTo(const char *mimeType); - void Unset(); - status_t InitCheck() const; + status_t SetTo(const char* mimeType); + void Unset(); + status_t InitCheck() const; - /* these functions simply perform string manipulations*/ - const char *Type() const; - bool IsValid() const; - bool IsSupertypeOnly() const; - status_t GetSupertype(BMimeType *superType) const; + /* these functions simply perform string manipulations*/ + const char* Type() const; + bool IsValid() const; + bool IsSupertypeOnly() const; + status_t GetSupertype(BMimeType* supertype) const; - bool operator==(const BMimeType &type) const; - bool operator==(const char *type) const; + bool operator==(const BMimeType &type) const; + bool operator==(const char* type) const; - bool Contains(const BMimeType *type) const; + bool Contains(const BMimeType* type) const; - /* These functions are for managing data in the meta mime file */ - status_t Install(); - status_t Delete(); - bool IsInstalled() const; - status_t GetIcon(BBitmap* icon, icon_size size) const; - status_t GetIcon(uint8** _data, size_t* _size) const; - status_t GetPreferredApp(char *signature, app_verb verb = B_OPEN) const; - status_t GetAttrInfo(BMessage *info) const; - status_t GetFileExtensions(BMessage *extensions) const; - status_t GetShortDescription(char *description) const; - status_t GetLongDescription(char *description) const; - status_t GetSupportingApps(BMessage *signatures) const; + /* These functions are for managing data in the meta mime file */ + status_t Install(); + status_t Delete(); + bool IsInstalled() const; + status_t GetIcon(BBitmap* icon, icon_size size) const; + status_t GetIcon(uint8** _data, size_t* _size) const; + status_t GetPreferredApp(char* signature, app_verb verb = B_OPEN) const; + status_t GetAttrInfo(BMessage* info) const; + status_t GetFileExtensions(BMessage* extensions) const; + status_t GetShortDescription(char* description) const; + status_t GetLongDescription(char* description) const; + status_t GetSupportingApps(BMessage* signatures) const; - status_t SetIcon(const BBitmap *icon, icon_size size); - status_t SetIcon(const uint8* data, size_t size); - status_t SetPreferredApp(const char *signature, app_verb verb = B_OPEN); - status_t SetAttrInfo(const BMessage *info); - status_t SetFileExtensions(const BMessage *extensions); - status_t SetShortDescription(const char *description); - status_t SetLongDescription(const char *description); + status_t SetIcon(const BBitmap* icon, icon_size size); + status_t SetIcon(const uint8* data, size_t size); + status_t SetPreferredApp(const char* signature, app_verb verb = B_OPEN); + status_t SetAttrInfo(const BMessage* info); + status_t SetFileExtensions(const BMessage* extensions); + status_t SetShortDescription(const char* description); + status_t SetLongDescription(const char* description); - static status_t GetInstalledSupertypes(BMessage *supertypes); - static status_t GetInstalledTypes(BMessage *types); - static status_t GetInstalledTypes(const char* supertype, - BMessage* subtypes); - static status_t GetWildcardApps(BMessage* wildcardApps); - static bool IsValid(const char *mimeType); + static status_t GetInstalledSupertypes(BMessage* supertypes); + static status_t GetInstalledTypes(BMessage* types); + static status_t GetInstalledTypes(const char* supertype, + BMessage* subtypes); + static status_t GetWildcardApps(BMessage* wildcardApps); + static bool IsValid(const char* mimeType); - status_t GetAppHint(entry_ref *ref) const; - status_t SetAppHint(const entry_ref *ref); + status_t GetAppHint(entry_ref* ref) const; + status_t SetAppHint(const entry_ref* ref); - /* for application signatures only. */ - status_t GetIconForType(const char* type, BBitmap* icon, - icon_size which) const; - status_t GetIconForType(const char* type, uint8** _data, - size_t* _size) const; - status_t SetIconForType(const char* type, const BBitmap* icon, - icon_size which); - status_t SetIconForType(const char* type, const uint8* data, - size_t size); + /* for application signatures only. */ + status_t GetIconForType(const char* type, BBitmap* icon, + icon_size which) const; + status_t GetIconForType(const char* type, uint8** _data, + size_t* _size) const; + status_t SetIconForType(const char* type, const BBitmap* icon, + icon_size which); + status_t SetIconForType(const char* type, const uint8* data, + size_t size); - /* sniffer rule manipulation */ - status_t GetSnifferRule(BString *result) const; - status_t SetSnifferRule(const char *); - static status_t CheckSnifferRule(const char *rule, BString *parseError); + /* sniffer rule manipulation */ + status_t GetSnifferRule(BString* result) const; + status_t SetSnifferRule(const char*); + static status_t CheckSnifferRule(const char* rule, BString* parseError); - /* calls to ask the sniffer to identify the MIME type of a file or data in - memory */ - static status_t GuessMimeType(const entry_ref *file, BMimeType *type); - static status_t GuessMimeType(const void *buffer, int32 length, - BMimeType *type); - static status_t GuessMimeType(const char *filename, BMimeType *type); + /* calls to ask the sniffer to identify the MIME type of a file or data in + memory */ + static status_t GuessMimeType(const entry_ref* file, BMimeType* type); + static status_t GuessMimeType(const void* buffer, int32 length, + BMimeType* type); + static status_t GuessMimeType(const char* filename, BMimeType* type); - static status_t StartWatching(BMessenger target); - static status_t StopWatching(BMessenger target); + static status_t StartWatching(BMessenger target); + static status_t StopWatching(BMessenger target); - /* Deprecated. Use SetTo() instead. */ - status_t SetType(const char *mimeType); + /* Deprecated. Use SetTo() instead. */ + status_t SetType(const char* mimeType); - private: - BMimeType(const char* mimeType, const char* mimePath); - // if mimePath is NULL, defaults to "/boot/home/config/settings/beos_mime/" +private: + BMimeType(const char* mimeType, const char* mimePath); + // if mimePath is NULL, defaults to "/boot/home/config/settings/beos_mime/" - friend class MimeTypeTest; - // for testing only + friend class MimeTypeTest; + // for testing only - friend class BAppFileInfo; + friend class BAppFileInfo; - virtual void _ReservedMimeType1(); - virtual void _ReservedMimeType2(); - virtual void _ReservedMimeType3(); + virtual void _ReservedMimeType1(); + virtual void _ReservedMimeType2(); + virtual void _ReservedMimeType3(); - BMimeType& operator=(const BMimeType& source); - BMimeType(const BMimeType& source); + BMimeType& operator=(const BMimeType& source); + BMimeType(const BMimeType& source); - status_t GetSupportedTypes(BMessage* types); - status_t SetSupportedTypes(const BMessage* types, bool fullSync = true); + status_t GetSupportedTypes(BMessage* types); + status_t SetSupportedTypes(const BMessage* types, bool fullSync = true); - static status_t GetAssociatedTypes(const char* extension, BMessage* types); + static status_t GetAssociatedTypes(const char* extension, BMessage* types); - private: - char* fType; - BFile* fMeta; - void* _unused; - entry_ref fRef; - status_t fCStatus; - uint32 _reserved[4]; +private: + char* fType; + BFile* fMeta; + void* _unused; + entry_ref fRef; + status_t fCStatus; + uint32 _reserved[4]; }; + #endif // _MIME_TYPE_H diff --git a/headers/os/storage/Node.h b/headers/os/storage/Node.h index 618d4aec0a..5b282494a8 100644 --- a/headers/os/storage/Node.h +++ b/headers/os/storage/Node.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2011 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _NODE_H @@ -18,12 +18,12 @@ struct entry_ref; struct node_ref { node_ref(); node_ref(dev_t device, ino_t node); - node_ref(const node_ref &ref); + node_ref(const node_ref &other); - bool operator==(const node_ref& ref) const; - bool operator!=(const node_ref& ref) const; - bool operator<(const node_ref& ref) const; - node_ref& operator=(const node_ref& ref); + bool operator==(const node_ref& other) const; + bool operator!=(const node_ref& other) const; + bool operator<(const node_ref& other) const; + node_ref& operator=(const node_ref& other); dev_t device; ino_t node; @@ -100,17 +100,21 @@ private: status_t _SetTo(int fd, const char* path, bool traverse); status_t _SetTo(const entry_ref* ref, bool traverse); - virtual status_t set_stat(struct stat& st, uint32 what); + virtual status_t set_stat(struct stat& stat, uint32 what); - status_t _GetStat(struct stat* st) const; - virtual status_t _GetStat(struct stat_beos* st) const; + status_t _GetStat(struct stat* stat) const; + virtual status_t _GetStat(struct stat_beos* stat) const; status_t InitAttrDir(); private: uint32 rudeData[4]; int fFd; + // Ffile descriptor for the given node int fAttrFd; + // file descriptor for the attribute directory of the node, + // initialized lazily status_t fCStatus; + // the node's initialization status }; diff --git a/headers/os/storage/NodeInfo.h b/headers/os/storage/NodeInfo.h index b82771c471..64e05f2496 100644 --- a/headers/os/storage/NodeInfo.h +++ b/headers/os/storage/NodeInfo.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _NODE_INFO_H @@ -31,9 +31,9 @@ public: virtual status_t GetType(char* type) const; virtual status_t SetType(const char* type); virtual status_t GetIcon(BBitmap* icon, - icon_size size = B_LARGE_ICON) const; + icon_size which = B_LARGE_ICON) const; virtual status_t SetIcon(const BBitmap* icon, - icon_size size = B_LARGE_ICON); + icon_size which = B_LARGE_ICON); status_t GetIcon(uint8** data, size_t* size, type_code* type) const; status_t SetIcon(const uint8* data, size_t size); @@ -46,10 +46,10 @@ public: status_t SetAppHint(const entry_ref* ref); status_t GetTrackerIcon(BBitmap* icon, - icon_size size = B_LARGE_ICON) const; + icon_size which = B_LARGE_ICON) const; static status_t GetTrackerIcon(const entry_ref* ref, BBitmap* icon, - icon_size size = B_LARGE_ICON); + icon_size which = B_LARGE_ICON); private: friend class BAppFileInfo; diff --git a/headers/os/storage/NodeMonitor.h b/headers/os/storage/NodeMonitor.h index cb66f15fc6..12d8f0bcf1 100644 --- a/headers/os/storage/NodeMonitor.h +++ b/headers/os/storage/NodeMonitor.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010, Haiku Inc. All Rights Reserved. + * Copyright 2003-2010 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _NODE_MONITOR_H @@ -32,25 +32,31 @@ enum { // The presence and meaning of the other fields in that message specifying what // exactly caused the notification depend on this value. -#define B_ENTRY_CREATED 1 -#define B_ENTRY_REMOVED 2 -#define B_ENTRY_MOVED 3 -#define B_STAT_CHANGED 4 -#define B_ATTR_CHANGED 5 -#define B_DEVICE_MOUNTED 6 -#define B_DEVICE_UNMOUNTED 7 +enum { + B_ENTRY_CREATED = 1, + B_ENTRY_REMOVED, + B_ENTRY_MOVED, + B_STAT_CHANGED, + B_ATTR_CHANGED, + B_DEVICE_MOUNTED, + B_DEVICE_UNMOUNTED +}; // More specific info in the "cause" field of B_ATTR_CHANGED notification // messages. (Haiku only) -#define B_ATTR_CREATED 1 -#define B_ATTR_REMOVED 2 -// B_ATTR_CHANGED is reused + +enum { + B_ATTR_CREATED = 1, + B_ATTR_REMOVED, +// B_ATTR_CHANGED +}; // More specific info in the "fields" field of B_STAT_CHANGED notification // messages, specifying what parts of the stat data have actually been // changed. (Haiku only) + enum { B_STAT_MODE = 0x0001, B_STAT_UID = 0x0002, @@ -82,16 +88,17 @@ class BHandler; extern status_t watch_volume(dev_t volume, uint32 flags, BMessenger target); extern status_t watch_volume(dev_t volume, uint32 flags, - const BHandler *handler, const BLooper *looper = NULL); + const BHandler* handler, const BLooper* looper = NULL); -extern status_t watch_node(const node_ref *node, uint32 flags, - BMessenger target); -extern status_t watch_node(const node_ref *node, uint32 flags, - const BHandler *handler, const BLooper *looper = NULL); +extern status_t watch_node(const node_ref* node, uint32 flags, + BMessenger target); +extern status_t watch_node(const node_ref* node, uint32 flags, + const BHandler* handler, const BLooper* looper = NULL); extern status_t stop_watching(BMessenger target); -extern status_t stop_watching(const BHandler *handler, const BLooper *looper = NULL); +extern status_t stop_watching(const BHandler* handler, const BLooper* looper = NULL); #endif // __cplusplus && !_KERNEL_MODE + #endif // _NODE_MONITOR_H diff --git a/headers/os/storage/Statable.h b/headers/os/storage/Statable.h index 099e730233..699ba0f735 100644 --- a/headers/os/storage/Statable.h +++ b/headers/os/storage/Statable.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2014 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _STATABLE_H @@ -18,58 +18,58 @@ class BVolume; class BStatable { - public: +public: #if __GNUC__ > 3 - virtual ~BStatable(); + virtual ~BStatable(); #endif private: - virtual status_t _GetStat(struct stat_beos *st) const = 0; - // provided for BeOS compatibility + virtual status_t _GetStat(struct stat_beos* stat) const = 0; + // provided for BeOS compatibility public: - virtual status_t GetStat(struct stat *st) const = 0; + virtual status_t GetStat(struct stat* stat) const = 0; - bool IsFile() const; - bool IsDirectory() const; - bool IsSymLink() const; + bool IsFile() const; + bool IsDirectory() const; + bool IsSymLink() const; - status_t GetNodeRef(node_ref *ref) const; + status_t GetNodeRef(node_ref* ref) const; - status_t GetOwner(uid_t *owner) const; - status_t SetOwner(uid_t owner); + status_t GetOwner(uid_t* owner) const; + status_t SetOwner(uid_t owner); - status_t GetGroup(gid_t *group) const; - status_t SetGroup(gid_t group); + status_t GetGroup(gid_t* group) const; + status_t SetGroup(gid_t group); - status_t GetPermissions(mode_t *perms) const; - status_t SetPermissions(mode_t perms); + status_t GetPermissions(mode_t* permissions) const; + status_t SetPermissions(mode_t permissions); - status_t GetSize(off_t *size) const; + status_t GetSize(off_t* size) const; - status_t GetModificationTime(time_t *mtime) const; - status_t SetModificationTime(time_t mtime); + status_t GetModificationTime(time_t* mtime) const; + status_t SetModificationTime(time_t mtime); - status_t GetCreationTime(time_t *ctime) const; - status_t SetCreationTime(time_t ctime); + status_t GetCreationTime(time_t* ctime) const; + status_t SetCreationTime(time_t ctime); - status_t GetAccessTime(time_t *atime) const; - status_t SetAccessTime(time_t atime); + status_t GetAccessTime(time_t* atime) const; + status_t SetAccessTime(time_t atime); - status_t GetVolume(BVolume *vol) const; + status_t GetVolume(BVolume* volume) const; - class Private; + class Private; - private: - friend class BEntry; - friend class BNode; - friend class Private; +private: + friend class BEntry; + friend class BNode; + friend class Private; - virtual void _OhSoStatable2(); - virtual void _OhSoStatable3(); - uint32 _reserved[4]; + virtual void _OhSoStatable2(); + virtual void _OhSoStatable3(); + uint32 _reserved[4]; - virtual status_t set_stat(struct stat &st, uint32 what) = 0; + virtual status_t set_stat(struct stat &st, uint32 what) = 0; }; #endif // _STATABLE_H diff --git a/headers/os/storage/SymLink.h b/headers/os/storage/SymLink.h index 89d379896a..e4b96008d4 100644 --- a/headers/os/storage/SymLink.h +++ b/headers/os/storage/SymLink.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2007 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _SYM_LINK_H @@ -16,20 +16,20 @@ class BPath; class BSymLink : public BNode { public: BSymLink(); - BSymLink(const BSymLink &link); - BSymLink(const entry_ref *ref); - BSymLink(const BEntry *entry); - BSymLink(const char *path); - BSymLink(const BDirectory *dir, - const char *path); + BSymLink(const BSymLink& other); + BSymLink(const entry_ref* ref); + BSymLink(const BEntry* entry); + BSymLink(const char* path); + BSymLink(const BDirectory* dir, + const char* path); virtual ~BSymLink(); - ssize_t ReadLink(char *buf, size_t size); + ssize_t ReadLink(char* buf, size_t size); - ssize_t MakeLinkedPath(const char *dirPath, - BPath *path); - ssize_t MakeLinkedPath(const BDirectory *dir, - BPath *path); + ssize_t MakeLinkedPath(const char* dirPath, + BPath* path); + ssize_t MakeLinkedPath(const BDirectory* dir, + BPath* path); bool IsAbsolute(); diff --git a/src/kits/storage/AppFileInfo.cpp b/src/kits/storage/AppFileInfo.cpp index 85165b440f..ef3ca1a74d 100644 --- a/src/kits/storage/AppFileInfo.cpp +++ b/src/kits/storage/AppFileInfo.cpp @@ -958,6 +958,7 @@ void BAppFileInfo::_ReservedAppFileInfo2() {} void BAppFileInfo::_ReservedAppFileInfo3() {} +//! Privatized assignment operator to prevent usage. BAppFileInfo& BAppFileInfo::operator=(const BAppFileInfo&) { @@ -965,11 +966,25 @@ BAppFileInfo::operator=(const BAppFileInfo&) } +//! Privatized copy constructor to prevent usage. BAppFileInfo::BAppFileInfo(const BAppFileInfo&) { } +/*! Initializes a BMimeType to the signature of the associated file. + + \warning The parameter \a meta is not checked. + + \param meta A pointer to a pre-allocated BMimeType that shall be + initialized to the signature of the associated file. + + \returns A status code. + \retval B_OK Everything went fine. + \retval B_BAD_VALUE \c NULL \a meta + \retval B_ENTRY_NOT_FOUND The file has not signature or the signature is + (not installed in the MIME database.) no valid MIME string. +*/ status_t BAppFileInfo::GetMetaMime(BMimeType* meta) const { @@ -985,6 +1000,31 @@ BAppFileInfo::GetMetaMime(BMimeType* meta) const } +/*! Reads data from an attribute or resource. + + \note The data is read from the location specified by \a fWhere. + + \warning The object must be properly initialized. The parameters are + \b NOT checked. + + \param name The name of the attribute/resource to be read. + \param id The resource ID of the resource to be read. It is ignored + when < 0. + \param type The type of the attribute/resource to be read. + \param buffer A pre-allocated buffer for the data to be read. + \param bufferSize The size of the supplied buffer. + \param bytesRead A reference parameter, set to the number of bytes + actually read. + \param allocatedBuffer If not \c NULL, the method allocates a buffer + large enough too store the whole data and writes a pointer to it + into this variable. If \c NULL, the supplied buffer is used. + + \returns A status code. + \retval B_OK Everything went fine. + \retval B_ENTRY_NOT_FOUND The entry was not found. + \retval B_NO_MEMORY Ran out of memory allocating the buffer. + \retval B_BAD_VALUE \a type did not match. +*/ status_t BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, void* buffer, size_t bufferSize, size_t& bytesRead, void** allocatedBuffer) @@ -1081,6 +1121,26 @@ BAppFileInfo::_ReadData(const char* name, int32 id, type_code type, } +/*! Writes data to an attribute or resource. + + \note The data is written to the location(s) specified by \a fWhere. + + \warning The object must be properly initialized. The parameters are + \b NOT checked. + + \param name The name of the attribute/resource to be written. + \param id The resource ID of the resource to be written. + \param type The type of the attribute/resource to be written. + \param buffer A buffer containing the data to be written. + \param bufferSize The size of the supplied buffer. + \param findID If set to \c true use the ID that is already assigned to the + \a name / \a type pair or take the first unused ID >= \a id. + If \c false, \a id is used. + + \returns A status code. + \retval B_OK Everything went fine. + \retval B_ERROR An error occurred while trying to write the data. +*/ status_t BAppFileInfo::_WriteData(const char* name, int32 id, type_code type, const void* buffer, size_t bufferSize, bool findID) @@ -1118,6 +1178,21 @@ BAppFileInfo::_WriteData(const char* name, int32 id, type_code type, } +/*! Removes an attribute or resource. + + \note The removal location is specified by \a fWhere. + + \warning The object must be properly initialized. The parameters are + \b NOT checked. + + \param name The name of the attribute/resource to be remove. + \param type The type of the attribute/resource to be removed. + + \returns A status code. + \retval B_OK Everything went fine. + \retval B_NO_INIT Not using attributes and not using resources. + \retval B_ENTRY_NOT_FOUND The attribute or resource was not found. +*/ status_t BAppFileInfo::_RemoveData(const char* name, type_code type) { diff --git a/src/kits/storage/Entry.cpp b/src/kits/storage/Entry.cpp index c078bee141..5edab8c819 100644 --- a/src/kits/storage/Entry.cpp +++ b/src/kits/storage/Entry.cpp @@ -502,6 +502,16 @@ void BEntry::_PennyEntry5(){} void BEntry::_PennyEntry6(){} +/*! Updates the BEntry with the data from the stat structure according + to the \a what mask. + + \param st The stat structure to set. + \param what A mask + + \returns A status code. + \retval B_OK Everything went fine. + \retval B_FILE_ERROR There was an error writing to the BEntry object. +*/ status_t BEntry::set_stat(struct stat& st, uint32 what) { @@ -513,6 +523,30 @@ BEntry::set_stat(struct stat& st, uint32 what) } +/*! Sets the entry to point to the entry specified by the path \a path + relative to the given directory. + + If \a traverse is \c true and the given entry is a symbolic link, the + object is recursively set to point to the entry pointed to by the symlink. + + If \a path is an absolute path, \a dirFD is ignored. + + If \a dirFD is -1, \a path is considered relative to the current directory + (unless it is an absolute path). + + The ownership of the file descriptor \a dirFD is transferred to the + method, regardless of whether it succeeds or fails. The caller must not + close the FD afterwards. + + \param dirFD File descriptor of a directory relative to which path is to + be considered. May be -1 if the current directory shall be considered. + \param path Pointer to a path relative to the given directory. + \param traverse If \c true and the given entry is a symbolic link, the + object is recursively set to point to the entry linked to by the + symbolic link. + + \returns \c B_OK on success, or an error code on failure. +*/ status_t BEntry::_SetTo(int dirFD, const char* path, bool traverse) { @@ -643,6 +677,16 @@ BEntry::_SetTo(int dirFD, const char* path, bool traverse) } +/*! Handles string allocation, deallocation, and copying for the + leaf name of the entry. + + \param name The leaf \a name of the entry. + + \returns A status code. + \retval B_OK Everything went fine. + \retval B_BAD_VALUE \a name is \c NULL. + \retval B_NO_MEMORY Ran out of memory trying to allocate \a name. +*/ status_t BEntry::_SetName(const char* name) { @@ -659,6 +703,22 @@ BEntry::_SetName(const char* name) } +/*! Renames the entry referred to by this object to the location + specified by \a target. + + If an entry exists at the target location, the method fails, unless + \a clobber is \c true, in which case that entry is overwritten (doesn't + work for non-empty directories, though). + + If the operation was successful, this entry is made a clone of the + supplied one and the supplied one is uninitialized. + + \param target The entry specifying the target location. + \param clobber If \c true, the an entry existing at the target location + will be overwritten. + + \return \c B_OK, if everything went fine, another error code otherwise. +*/ status_t BEntry::_Rename(BEntry& target, bool clobber) { @@ -680,6 +740,11 @@ BEntry::_Rename(BEntry& target, bool clobber) } +/*! Debugging function, dumps the given entry to stdout. + + \param name A pointer to a string to be printed along with the dump for + identification purposes. +*/ void BEntry::_Dump(const char* name) { diff --git a/src/kits/storage/File.cpp b/src/kits/storage/File.cpp index 5de260233b..a3a0ceab9f 100644 --- a/src/kits/storage/File.cpp +++ b/src/kits/storage/File.cpp @@ -337,7 +337,12 @@ void BFile::_PhiloFile5() {} void BFile::_PhiloFile6() {} -// Gets the file descriptor of the BFile. +/*! Gets the file descriptor of the BFile. + + To be used instead of accessing the BNode's private \c fFd member directly. + + \returns The file descriptor, or -1 if not properly initialized. +*/ int BFile::get_fd() const { @@ -345,7 +350,7 @@ BFile::get_fd() const } -// Overrides BNode::close_fd() for binary compatibility with BeOS R5. +//! Overrides BNode::close_fd() for binary compatibility with BeOS R5. void BFile::close_fd() { diff --git a/src/kits/storage/Mime.cpp b/src/kits/storage/Mime.cpp index c8c34e1ad7..aca9e25356 100644 --- a/src/kits/storage/Mime.cpp +++ b/src/kits/storage/Mime.cpp @@ -8,10 +8,6 @@ * Axel Dörfler, axeld@pinc-software.de */ -/*! - \file Mime.cpp - Mime type C functions implementation. -*/ #include #include @@ -47,7 +43,7 @@ enum { // Helper function that contacts the registrar for mime update calls status_t -do_mime_update(int32 what, const char *path, int recursive, +do_mime_update(int32 what, const char* path, int recursive, int synchronous, int force) { BEntry root; @@ -85,7 +81,7 @@ do_mime_update(int32 what, const char *path, int recursive, // Updates the MIME information (i.e MIME type) for one or more files. int -update_mime_info(const char *path, int recursive, int synchronous, int force) +update_mime_info(const char* path, int recursive, int synchronous, int force) { // Force recursion when given a NULL path if (!path) @@ -98,7 +94,7 @@ update_mime_info(const char *path, int recursive, int synchronous, int force) // Creates a MIME database entry for one or more applications. status_t -create_app_meta_mime(const char *path, int recursive, int synchronous, +create_app_meta_mime(const char* path, int recursive, int synchronous, int force) { // Force recursion when given a NULL path @@ -112,7 +108,7 @@ create_app_meta_mime(const char *path, int recursive, int synchronous, // Retrieves an icon associated with a given device. status_t -get_device_icon(const char *device, void *icon, int32 size) +get_device_icon(const char* device, void* icon, int32 size) { if (device == NULL || icon == NULL || (size != B_LARGE_ICON && size != B_MINI_ICON)) @@ -169,7 +165,7 @@ get_device_icon(const char *device, void *icon, int32 size) // Retrieves an icon associated with a given device. status_t -get_device_icon(const char *device, BBitmap *icon, icon_size which) +get_device_icon(const char* device, BBitmap* icon, icon_size which) { // check parameters if (device == NULL || icon == NULL) @@ -225,7 +221,7 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which) status_t -get_device_icon(const char *device, uint8** _data, size_t* _size, +get_device_icon(const char* device, uint8** _data, size_t* _size, type_code* _type) { if (device == NULL || _data == NULL || _size == NULL || _type == NULL) diff --git a/src/kits/storage/MimeType.cpp b/src/kits/storage/MimeType.cpp index b10842188c..4b4c350867 100644 --- a/src/kits/storage/MimeType.cpp +++ b/src/kits/storage/MimeType.cpp @@ -1,11 +1,11 @@ /* - * Copyright 2002-2006, Haiku Inc. + * Copyright 2002-2006 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: + * Axel Dörfler, axeld@pinc-software.de * Tyler Dauwalder * Ingo Weinhold, bonefish@users.sf.net - * Axel Dörfler, axeld@pinc-software.de */ @@ -34,14 +34,14 @@ static bool isValidMimeChar(const char ch); using namespace BPrivate::Storage::Mime; using namespace std; -const char *B_PEF_APP_MIME_TYPE = "application/x-be-executable"; -const char *B_PE_APP_MIME_TYPE = "application/x-vnd.Be-peexecutable"; -const char *B_ELF_APP_MIME_TYPE = "application/x-vnd.Be-elfexecutable"; -const char *B_RESOURCE_MIME_TYPE = "application/x-be-resource"; -const char *B_FILE_MIME_TYPE = "application/octet-stream"; +const char* B_PEF_APP_MIME_TYPE = "application/x-be-executable"; +const char* B_PE_APP_MIME_TYPE = "application/x-vnd.Be-peexecutable"; +const char* B_ELF_APP_MIME_TYPE = "application/x-vnd.Be-elfexecutable"; +const char* B_RESOURCE_MIME_TYPE = "application/x-be-resource"; +const char* B_FILE_MIME_TYPE = "application/octet-stream"; // Might be defined platform depended, but ELF will certainly be the common // format for all platforms anyway. -const char *B_APP_MIME_TYPE = B_ELF_APP_MIME_TYPE; +const char* B_APP_MIME_TYPE = B_ELF_APP_MIME_TYPE; static bool @@ -82,7 +82,7 @@ BMimeType::BMimeType() // Creates a BMimeType object and initializes it to the supplied // MIME type. -BMimeType::BMimeType(const char *mimeType) +BMimeType::BMimeType(const char* mimeType) : fType(NULL), fCStatus(B_NO_INIT) @@ -100,7 +100,7 @@ BMimeType::~BMimeType() // Initializes this object to the supplied MIME type. status_t -BMimeType::SetTo(const char *mimeType) +BMimeType::SetTo(const char* mimeType) { if (mimeType == NULL) { Unset(); @@ -184,12 +184,12 @@ BMimeType::IsInstalled() const // Gets the supertype of the MIME type represented by this object status_t -BMimeType::GetSupertype(BMimeType *superType) const +BMimeType::GetSupertype(BMimeType* supertype) const { - if (superType == NULL) + if (supertype == NULL) return B_BAD_VALUE; - superType->Unset(); + supertype->Unset(); status_t status = fCStatus == B_OK ? B_OK : B_BAD_VALUE; if (status == B_OK) { size_t len = strlen(fType); @@ -205,7 +205,7 @@ BMimeType::GetSupertype(BMimeType *superType) const char superMime[B_MIME_TYPE_LENGTH]; strncpy(superMime, fType, i); superMime[i] = 0; - status = superType->SetTo(superMime) == B_OK ? B_OK : B_BAD_VALUE; + status = supertype->SetTo(superMime) == B_OK ? B_OK : B_BAD_VALUE; } } @@ -228,11 +228,12 @@ BMimeType::operator==(const BMimeType &type) const // Returns whether this and the supplied MIME type are equal bool -BMimeType::operator==(const char *type) const +BMimeType::operator==(const char* type) const { BMimeType mime; if (type) mime.SetTo(type); + return (*this) == mime; } @@ -240,16 +241,18 @@ BMimeType::operator==(const char *type) const // Returns whether this MIME type is a supertype of or equals the // supplied one bool -BMimeType::Contains(const BMimeType *type) const +BMimeType::Contains(const BMimeType* type) const { - if (!type) + if (type == NULL) return false; + if (*this == *type) return true; + BMimeType super; if (type->GetSupertype(&super) == B_OK && *this == super) return true; - return false; + return false; } @@ -259,23 +262,27 @@ BMimeType::Install() { status_t err = InitCheck(); - BMessage msg(B_REG_MIME_INSTALL); + BMessage message(B_REG_MIME_INSTALL); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; - return err; + return err; } @@ -285,20 +292,24 @@ BMimeType::Delete() { status_t err = InitCheck(); - BMessage msg(B_REG_MIME_DELETE); + BMessage message(B_REG_MIME_DELETE); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -307,13 +318,13 @@ BMimeType::Delete() // Fetches the large or mini icon associated with the MIME type status_t -BMimeType::GetIcon(BBitmap *icon, icon_size size) const +BMimeType::GetIcon(BBitmap* icon, icon_size size) const { if (icon == NULL) return B_BAD_VALUE; status_t err = InitCheck(); - if (!err) + if (err == B_OK) err = default_database_location()->GetIcon(Type(), *icon, size); return err; @@ -328,7 +339,7 @@ BMimeType::GetIcon(uint8** data, size_t* size) const return B_BAD_VALUE; status_t err = InitCheck(); - if (!err) + if (err == B_OK) err = default_database_location()->GetIcon(Type(), *data, *size); return err; @@ -338,10 +349,10 @@ BMimeType::GetIcon(uint8** data, size_t* size) const // Fetches the signature of the MIME type's preferred application from the // MIME database status_t -BMimeType::GetPreferredApp(char *signature, app_verb verb) const +BMimeType::GetPreferredApp(char* signature, app_verb verb) const { status_t err = InitCheck(); - if (!err) { + if (err == B_OK) { err = default_database_location()->GetPreferredApp(Type(), signature, verb); } @@ -353,13 +364,13 @@ BMimeType::GetPreferredApp(char *signature, app_verb verb) const // Fetches from the MIME database a BMessage describing the attributes // typically associated with files of the given MIME type status_t -BMimeType::GetAttrInfo(BMessage *info) const +BMimeType::GetAttrInfo(BMessage* info) const { if (info == NULL) return B_BAD_VALUE; status_t err = InitCheck(); - if (!err) + if (err == B_OK) err = default_database_location()->GetAttributesInfo(Type(), *info); return err; @@ -369,13 +380,13 @@ BMimeType::GetAttrInfo(BMessage *info) const // Fetches the MIME type's associated filename extensions from the MIME // database status_t -BMimeType::GetFileExtensions(BMessage *extensions) const +BMimeType::GetFileExtensions(BMessage* extensions) const { if (extensions == NULL) return B_BAD_VALUE; status_t err = InitCheck(); - if (!err) { + if (err == B_OK) { err = default_database_location()->GetFileExtensions(Type(), *extensions); } @@ -386,10 +397,10 @@ BMimeType::GetFileExtensions(BMessage *extensions) const // Fetches the MIME type's short description from the MIME database status_t -BMimeType::GetShortDescription(char *description) const +BMimeType::GetShortDescription(char* description) const { status_t err = InitCheck(); - if (!err) { + if (err == B_OK) { err = default_database_location()->GetShortDescription(Type(), description); } @@ -400,10 +411,10 @@ BMimeType::GetShortDescription(char *description) const // Fetches the MIME type's long description from the MIME database status_t -BMimeType::GetLongDescription(char *description) const +BMimeType::GetLongDescription(char* description) const { status_t err = InitCheck(); - if (!err) { + if (err == B_OK) { err = default_database_location()->GetLongDescription(Type(), description); } @@ -415,26 +426,26 @@ BMimeType::GetLongDescription(char *description) const // Fetches a \c BMessage containing a list of MIME signatures of // applications that are able to handle files of this MIME type. status_t -BMimeType::GetSupportingApps(BMessage *signatures) const +BMimeType::GetSupportingApps(BMessage* signatures) const { if (signatures == NULL) return B_BAD_VALUE; - BMessage msg(B_REG_MIME_GET_SUPPORTING_APPS); + BMessage message(B_REG_MIME_GET_SUPPORTING_APPS); status_t result; status_t err = InitCheck(); - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = BRoster::Private().SendTo(&msg, signatures, true); - if (!err) { + if (err == B_OK) + err = message.AddString("type", Type()); + if (err == B_OK) + err = BRoster::Private().SendTo(&message, signatures, true); + if (err == B_OK) { err = (status_t)(signatures->what == B_REG_RESULT ? B_OK : B_BAD_REPLY); } - if (!err) + if (err == B_OK) err = signatures->FindInt32("result", &result); - if (!err) + if (err == B_OK) err = result; return err; @@ -443,7 +454,7 @@ BMimeType::GetSupportingApps(BMessage *signatures) const // Sets the large or mini icon for the MIME type status_t -BMimeType::SetIcon(const BBitmap *icon, icon_size which) +BMimeType::SetIcon(const BBitmap* icon, icon_size which) { return SetIconForType(NULL, icon, which); } @@ -459,31 +470,38 @@ BMimeType::SetIcon(const uint8* data, size_t size) // Sets the preferred application for the MIME type status_t -BMimeType::SetPreferredApp(const char *signature, app_verb verb) +BMimeType::SetPreferredApp(const char* signature, app_verb verb) { status_t err = InitCheck(); - BMessage msg(signature && signature[0] + BMessage message(signature && signature[0] ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_PREFERRED_APP); - if (!err && signature) - err = msg.AddString("signature", signature); - if (!err) - err = msg.AddInt32("app verb", verb); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_PREFERRED_APP); + + if (err == B_OK && signature != NULL) + err = message.AddString("signature", signature); + + if (err == B_OK) + err = message.AddInt32("app verb", verb); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -493,28 +511,28 @@ BMimeType::SetPreferredApp(const char *signature, app_verb verb) // Sets the description of the attributes typically associated with files // of the given MIME type status_t -BMimeType::SetAttrInfo(const BMessage *info) +BMimeType::SetAttrInfo(const BMessage* info) { status_t err = InitCheck(); - BMessage msg(info ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); + BMessage message(info ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_ATTR_INFO); - if (!err && info) - err = msg.AddMessage("attr info", info); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_ATTR_INFO); + if (err == B_OK && info != NULL) + err = message.AddMessage("attr info", info); + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + if (err == B_OK) err = result; return err; @@ -523,28 +541,34 @@ BMimeType::SetAttrInfo(const BMessage *info) // Sets the list of filename extensions associated with the MIME type status_t -BMimeType::SetFileExtensions(const BMessage *extensions) +BMimeType::SetFileExtensions(const BMessage* extensions) { status_t err = InitCheck(); - BMessage msg(extensions ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); + BMessage message(extensions ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_FILE_EXTENSIONS); - if (!err && extensions) - err = msg.AddMessage("extensions", extensions); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_FILE_EXTENSIONS); + + if (err != B_OK && extensions != NULL) + err = message.AddMessage("extensions", extensions); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -553,31 +577,38 @@ BMimeType::SetFileExtensions(const BMessage *extensions) // Sets the short description field for the MIME type status_t -BMimeType::SetShortDescription(const char *description) +BMimeType::SetShortDescription(const char* description) { status_t err = InitCheck(); - BMessage msg(description && description [0] + BMessage message(description && description [0] ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_DESCRIPTION); - if (!err && description) - err = msg.AddString("description", description); - if (!err) - err = msg.AddBool("long", false); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_DESCRIPTION); + + if (err == B_OK && description) + err = message.AddString("description", description); + + if (err == B_OK) + err = message.AddBool("long", false); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -586,31 +617,38 @@ BMimeType::SetShortDescription(const char *description) // Sets the long description field for the MIME type status_t -BMimeType::SetLongDescription(const char *description) +BMimeType::SetLongDescription(const char* description) { status_t err = InitCheck(); - BMessage msg(description && description[0] + BMessage message(description && description[0] ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_DESCRIPTION); - if (!err && description) - err = msg.AddString("description", description); - if (!err) - err = msg.AddBool("long", true); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_DESCRIPTION); + + if (err == B_OK && description) + err = message.AddString("description", description); + + if (err == B_OK) + err = message.AddBool("long", true); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -620,32 +658,32 @@ BMimeType::SetLongDescription(const char *description) // Fetches a BMessage listing all the MIME supertypes currently // installed in the MIME database. /*static*/ status_t -BMimeType::GetInstalledSupertypes(BMessage *supertypes) +BMimeType::GetInstalledSupertypes(BMessage* supertypes) { if (supertypes == NULL) return B_BAD_VALUE; - BMessage msg(B_REG_MIME_GET_INSTALLED_SUPERTYPES); + BMessage message(B_REG_MIME_GET_INSTALLED_SUPERTYPES); status_t result; - status_t err = BRoster::Private().SendTo(&msg, supertypes, true); - if (!err) { + status_t err = BRoster::Private().SendTo(&message, supertypes, true); + if (err == B_OK) { err = (status_t)(supertypes->what == B_REG_RESULT ? B_OK : B_BAD_REPLY); } - if (!err) + if (err == B_OK) err = supertypes->FindInt32("result", &result); - if (!err) + if (err == B_OK) err = result; - return err; + return err; } // Fetches a BMessage listing all the MIME types currently installed // in the MIME database. status_t -BMimeType::GetInstalledTypes(BMessage *types) +BMimeType::GetInstalledTypes(BMessage* types) { return GetInstalledTypes(NULL, types); } @@ -654,7 +692,7 @@ BMimeType::GetInstalledTypes(BMessage *types) // Fetches a BMessage listing all the MIME subtypes of the given // supertype currently installed in the MIME database. /*static*/ status_t -BMimeType::GetInstalledTypes(const char *supertype, BMessage *types) +BMimeType::GetInstalledTypes(const char* supertype, BMessage* types) { if (types == NULL) return B_BAD_VALUE; @@ -662,18 +700,18 @@ BMimeType::GetInstalledTypes(const char *supertype, BMessage *types) status_t result; // Build and send the message, read the reply - BMessage msg(B_REG_MIME_GET_INSTALLED_TYPES); + BMessage message(B_REG_MIME_GET_INSTALLED_TYPES); status_t err = B_OK; if (supertype != NULL) - err = msg.AddString("supertype", supertype); - if (!err) - err = BRoster::Private().SendTo(&msg, types, true); - if (!err) + err = message.AddString("supertype", supertype); + if (err == B_OK) + err = BRoster::Private().SendTo(&message, types, true); + if (err == B_OK) err = (status_t)(types->what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + if (err == B_OK) err = types->FindInt32("result", &result); - if (!err) + if (err == B_OK) err = result; return err; @@ -683,11 +721,11 @@ BMimeType::GetInstalledTypes(const char *supertype, BMessage *types) // Fetches a \c BMessage containing a list of MIME signatures of // applications that are able to handle files of any type. status_t -BMimeType::GetWildcardApps(BMessage *wild_ones) +BMimeType::GetWildcardApps(BMessage* wild_ones) { BMimeType mime; status_t err = mime.SetTo("application/octet-stream"); - if (!err) + if (err == B_OK) err = mime.GetSupportingApps(wild_ones); return err; } @@ -695,7 +733,7 @@ BMimeType::GetWildcardApps(BMessage *wild_ones) // Returns whether the given string represents a valid MIME type. bool -BMimeType::IsValid(const char *string) +BMimeType::IsValid(const char* string) { if (string == NULL) return false; @@ -723,13 +761,13 @@ BMimeType::IsValid(const char *string) // Fetches an \c entry_ref that serves as a hint as to where the MIME type's // preferred application might live status_t -BMimeType::GetAppHint(entry_ref *ref) const +BMimeType::GetAppHint(entry_ref* ref) const { if (ref == NULL) return B_BAD_VALUE; status_t err = InitCheck(); - if (!err) + if (err == B_OK) err = default_database_location()->GetAppHint(Type(), *ref); return err; } @@ -737,28 +775,34 @@ BMimeType::GetAppHint(entry_ref *ref) const // Sets the app hint field for the MIME type status_t -BMimeType::SetAppHint(const entry_ref *ref) +BMimeType::SetAppHint(const entry_ref* ref) { status_t err = InitCheck(); - BMessage msg(ref ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); + BMessage message(ref ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_APP_HINT); - if (!err && ref) - err = msg.AddRef("app hint", ref); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_APP_HINT); + + if (err == B_OK && ref != NULL) + err = message.AddRef("app hint", ref); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -768,7 +812,7 @@ BMimeType::SetAppHint(const entry_ref *ref) // Fetches the large or mini icon used by an application of this type for // files of the given type. status_t -BMimeType::GetIconForType(const char *type, BBitmap *icon, icon_size which) const +BMimeType::GetIconForType(const char* type, BBitmap* icon, icon_size which) const { if (icon == NULL) return B_BAD_VALUE; @@ -778,7 +822,7 @@ BMimeType::GetIconForType(const char *type, BBitmap *icon, icon_size which) cons status_t err; if (type) { err = BMimeType::IsValid(type) ? B_OK : B_BAD_VALUE; - if (!err) { + if (err == B_OK) { err = default_database_location()->GetIconForType(Type(), type, *icon, which); } @@ -792,7 +836,7 @@ BMimeType::GetIconForType(const char *type, BBitmap *icon, icon_size which) cons // Fetches the vector icon used by an application of this type for files of // the given type. status_t -BMimeType::GetIconForType(const char *type, uint8** _data, size_t* _size) const +BMimeType::GetIconForType(const char* type, uint8** _data, size_t* _size) const { if (_data == NULL || _size == NULL) return B_BAD_VALUE; @@ -813,47 +857,58 @@ BMimeType::GetIconForType(const char *type, uint8** _data, size_t* _size) const // Sets the large or mini icon used by an application of this type for // files of the given type. status_t -BMimeType::SetIconForType(const char *type, const BBitmap *icon, icon_size which) +BMimeType::SetIconForType(const char* type, const BBitmap* icon, icon_size which) { status_t err = InitCheck(); - BMessage msg(icon ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); + BMessage message(icon ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; - - void *data = NULL; - int32 dataSize; - + + void* data = NULL; + int32 dataSize; + // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) { + err = message.AddInt32("which", type ? B_REG_MIME_ICON_FOR_TYPE : B_REG_MIME_ICON); - if (icon) { - if (!err) + } + + if (icon != NULL) { + if (err == B_OK) err = get_icon_data(icon, which, &data, &dataSize); - if (!err) - err = msg.AddData("icon data", B_RAW_TYPE, data, dataSize); + + if (err == B_OK) + err = message.AddData("icon data", B_RAW_TYPE, data, dataSize); } - if (!err) - err = msg.AddInt32("icon size", which); - if (type) { - if (!err) + + if (err == B_OK) + err = message.AddInt32("icon size", which); + + if (type != NULL) { + if (err == B_OK) err = BMimeType::IsValid(type) ? B_OK : B_BAD_VALUE; - if (!err) - err = msg.AddString("file type", type); + + if (err == B_OK) + err = message.AddString("file type", type); } - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; - delete [] (int8*)data; + delete[] (int8*)data; return err; } @@ -866,35 +921,35 @@ BMimeType::SetIconForType(const char* type, const uint8* data, size_t dataSize) { status_t err = InitCheck(); - BMessage msg(data ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); + BMessage message(data ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; - + // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", (type ? B_REG_MIME_ICON_FOR_TYPE : B_REG_MIME_ICON)); + if (err == B_OK) + err = message.AddString("type", Type()); + if (err == B_OK) + err = message.AddInt32("which", (type ? B_REG_MIME_ICON_FOR_TYPE : B_REG_MIME_ICON)); if (data) { - if (!err) - err = msg.AddData("icon data", B_RAW_TYPE, data, dataSize); + if (err == B_OK) + err = message.AddData("icon data", B_RAW_TYPE, data, dataSize); } - if (!err) - err = msg.AddInt32("icon size", -1); + if (err == B_OK) + err = message.AddInt32("icon size", -1); // -1 indicates size should be ignored (vector icon data) if (type) { - if (!err) + if (err == B_OK) err = BMimeType::IsValid(type) ? B_OK : B_BAD_VALUE; - if (!err) - err = msg.AddString("file type", type); + if (err == B_OK) + err = message.AddString("file type", type); } - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + if (err == B_OK) err = result; return err; @@ -903,13 +958,13 @@ BMimeType::SetIconForType(const char* type, const uint8* data, size_t dataSize) // Retrieves the MIME type's sniffer rule status_t -BMimeType::GetSnifferRule(BString *result) const +BMimeType::GetSnifferRule(BString* result) const { if (result == NULL) return B_BAD_VALUE; status_t err = InitCheck(); - if (!err) + if (err == B_OK) err = default_database_location()->GetSnifferRule(Type(), *result); return err; @@ -918,32 +973,38 @@ BMimeType::GetSnifferRule(BString *result) const // Sets the MIME type's sniffer rule status_t -BMimeType::SetSnifferRule(const char *rule) +BMimeType::SetSnifferRule(const char* rule) { status_t err = InitCheck(); - if (!err && rule && rule[0]) + if (err == B_OK && rule != NULL && rule[0] != '\0') err = CheckSnifferRule(rule, NULL); + if (err != B_OK) return err; - BMessage msg(rule && rule[0] ? B_REG_MIME_SET_PARAM + BMessage message(rule && rule[0] ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; // Build and send the message, read the reply - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_SNIFFER_RULE); - if (!err && rule) - err = msg.AddString("sniffer rule", rule); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + err = message.AddString("type", Type()); + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_SNIFFER_RULE); + + if (err == B_OK && rule) + err = message.AddString("sniffer rule", rule); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -952,7 +1013,7 @@ BMimeType::SetSnifferRule(const char *rule) // Checks whether a MIME sniffer rule is valid or not. status_t -BMimeType::CheckSnifferRule(const char *rule, BString *parseError) +BMimeType::CheckSnifferRule(const char* rule, BString* parseError) { BPrivate::Storage::Sniffer::Rule snifferRule; @@ -963,29 +1024,35 @@ BMimeType::CheckSnifferRule(const char *rule, BString *parseError) // Guesses a MIME type for the entry referred to by the given // entry_ref. status_t -BMimeType::GuessMimeType(const entry_ref *file, BMimeType *type) +BMimeType::GuessMimeType(const entry_ref* file, BMimeType* type) { status_t err = file && type ? B_OK : B_BAD_VALUE; - BMessage msg(B_REG_MIME_SNIFF); + BMessage message(B_REG_MIME_SNIFF); BMessage reply; status_t result; - const char *str; + const char* str; // Build and send the message, read the reply - if (!err) - err = msg.AddRef("file ref", file); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddRef("file ref", file); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; - if (!err) + + if (err == B_OK) err = reply.FindString("mime type", &str); - if (!err) + + if (err == B_OK) err = type->SetTo(str); return err; @@ -994,29 +1061,35 @@ BMimeType::GuessMimeType(const entry_ref *file, BMimeType *type) // Guesses a MIME type for the supplied chunk of data. status_t -BMimeType::GuessMimeType(const void *buffer, int32 length, BMimeType *type) +BMimeType::GuessMimeType(const void* buffer, int32 length, BMimeType* type) { status_t err = buffer && type ? B_OK : B_BAD_VALUE; - BMessage msg(B_REG_MIME_SNIFF); + BMessage message(B_REG_MIME_SNIFF); BMessage reply; status_t result; - const char *str; + const char* str; // Build and send the message, read the reply - if (!err) - err = msg.AddData("data", B_RAW_TYPE, buffer, length); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddData("data", B_RAW_TYPE, buffer, length); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; - if (!err) + + if (err == B_OK) err = reply.FindString("mime type", &str); - if (!err) + + if (err == B_OK) err = type->SetTo(str); return err; @@ -1025,29 +1098,35 @@ BMimeType::GuessMimeType(const void *buffer, int32 length, BMimeType *type) // Guesses a MIME type for the given filename. status_t -BMimeType::GuessMimeType(const char *filename, BMimeType *type) +BMimeType::GuessMimeType(const char* filename, BMimeType* type) { status_t err = filename && type ? B_OK : B_BAD_VALUE; - BMessage msg(B_REG_MIME_SNIFF); + BMessage message(B_REG_MIME_SNIFF); BMessage reply; status_t result; - const char *str; - + const char* str; + // Build and send the message, read the reply - if (!err) - err = msg.AddString("filename", filename); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("filename", filename); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; - if (!err) + + if (err == B_OK) err = reply.FindString("mime type", &str); - if (!err) + + if (err == B_OK) err = type->SetTo(str); return err; @@ -1058,20 +1137,23 @@ BMimeType::GuessMimeType(const char *filename, BMimeType *type) status_t BMimeType::StartWatching(BMessenger target) { - BMessage msg(B_REG_MIME_START_WATCHING); + BMessage message(B_REG_MIME_START_WATCHING); BMessage reply; status_t result; status_t err; // Build and send the message, read the reply - err = msg.AddMessenger("target", target); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + err = message.AddMessenger("target", target); + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; @@ -1082,28 +1164,32 @@ BMimeType::StartWatching(BMessenger target) status_t BMimeType::StopWatching(BMessenger target) { - BMessage msg(B_REG_MIME_STOP_WATCHING); + BMessage message(B_REG_MIME_STOP_WATCHING); BMessage reply; status_t result; status_t err; // Build and send the message, read the reply - err = msg.AddMessenger("target", target); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + err = message.AddMessenger("target", target); + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; } + // Initializes this object to the supplied MIME type status_t -BMimeType::SetType(const char *mimeType) +BMimeType::SetType(const char* mimeType) { return SetTo(mimeType); } @@ -1119,7 +1205,8 @@ void BMimeType::_ReservedMimeType3() {} BMimeType& BMimeType::operator=(const BMimeType &) { - return *this; // not implemented + return *this; + // not implemented } @@ -1131,72 +1218,122 @@ BMimeType::BMimeType(const BMimeType &) status_t -BMimeType::GetSupportedTypes(BMessage *types) +BMimeType::GetSupportedTypes(BMessage* types) { if (types == NULL) return B_BAD_VALUE; status_t err = InitCheck(); - if (!err) + if (err == B_OK) err = default_database_location()->GetSupportedTypes(Type(), *types); return err; } -// Sets the list of MIME types supported by the MIME type +/*! Sets the list of MIME types supported by the MIME type (which is + assumed to be an application signature). + + If \a types is \c NULL the application's supported types are unset. + + The supported MIME types must be stored in a field "types" of type + \c B_STRING_TYPE in \a types. + + For each supported type the result of BMimeType::GetSupportingApps() will + afterwards include the signature of this application. + + \a fullSync specifies whether or not any types that are no longer + listed as supported types as of this call to SetSupportedTypes() shall be + updated as well, i.e. whether this application shall be removed from their + lists of supporting applications. + + If \a fullSync is \c false, this application will not be removed from the + previously supported types' supporting apps lists until the next call + to BMimeType::SetSupportedTypes() or BMimeType::DeleteSupportedTypes() + with a \c true \a fullSync parameter, the next call to BMimeType::Delete(), + or the next reboot. + + \param types The supported types to be assigned to the file. + May be \c NULL. + \param fullSync \c true to also synchronize the previously supported + types, \c false otherwise. + + \returns \c B_OK on success or another error code on failure. +*/ status_t -BMimeType::SetSupportedTypes(const BMessage *types, bool fullSync) +BMimeType::SetSupportedTypes(const BMessage* types, bool fullSync) { status_t err = InitCheck(); - BMessage msg(types ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); + // Build and send the message, read the reply + BMessage message(types ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM); BMessage reply; status_t result; - // Build and send the message, read the reply - if (!err) - err = msg.AddString("type", Type()); - if (!err) - err = msg.AddInt32("which", B_REG_MIME_SUPPORTED_TYPES); - if (!err && types) - err = msg.AddMessage("types", types); - if (!err) - err = msg.AddBool("full sync", fullSync); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("type", Type()); + + if (err == B_OK) + err = message.AddInt32("which", B_REG_MIME_SUPPORTED_TYPES); + + if (err != B_OK && types != NULL) + err = message.AddMessage("types", types); + + if (err == B_OK) + err = message.AddBool("full sync", fullSync); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; return err; } -// Returns a list of mime types associated with the given file extension +/*! Returns a list of mime types associated with the given file extension + + The list of types is returned in the pre-allocated \c BMessage pointed to + by \a types. The types are stored in the message's "types" field, which + is an array of \c B_STRING_TYPE values. + + \param extension The file extension of interest + \param types Pointer to a pre-allocated BMessage into which the result will + be stored. + + \returns \c B_OK on success or another error code on failure. +*/ status_t -BMimeType::GetAssociatedTypes(const char *extension, BMessage *types) +BMimeType::GetAssociatedTypes(const char* extension, BMessage* types) { status_t err = extension && types ? B_OK : B_BAD_VALUE; - BMessage msg(B_REG_MIME_GET_ASSOCIATED_TYPES); + BMessage message(B_REG_MIME_GET_ASSOCIATED_TYPES); BMessage &reply = *types; status_t result; // Build and send the message, read the reply - if (!err) - err = msg.AddString("extension", extension); - if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); - if (!err) + if (err == B_OK) + err = message.AddString("extension", extension); + + if (err == B_OK) + err = BRoster::Private().SendTo(&message, &reply, true); + + if (err == B_OK) err = (status_t)(reply.what == B_REG_RESULT ? B_OK : B_BAD_REPLY); - if (!err) + + if (err == B_OK) err = reply.FindInt32("result", &result); - if (!err) + + if (err == B_OK) err = result; - return err; + return err; } diff --git a/src/kits/storage/Node.cpp b/src/kits/storage/Node.cpp index 83ce9dc59d..5ecc21fe30 100644 --- a/src/kits/storage/Node.cpp +++ b/src/kits/storage/Node.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011, Haiku Inc. + * Copyright 2002-2011 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -33,8 +33,9 @@ node_ref::node_ref() - : device((dev_t)-1), - node((ino_t)-1) + : + device((dev_t)-1), + node((ino_t)-1) { } @@ -47,25 +48,26 @@ node_ref::node_ref(dev_t device, ino_t node) } -node_ref::node_ref(const node_ref &ref) - : device((dev_t)-1), - node((ino_t)-1) +node_ref::node_ref(const node_ref& other) + : + device((dev_t)-1), + node((ino_t)-1) { - *this = ref; + *this = other; } -// == + bool -node_ref::operator==(const node_ref &ref) const +node_ref::operator==(const node_ref& other) const { - return (device == ref.device && node == ref.node); + return (device == other.device && node == other.node); } -// != + bool -node_ref::operator!=(const node_ref &ref) const +node_ref::operator!=(const node_ref& other) const { - return !(*this == ref); + return !(*this == other); } @@ -74,16 +76,16 @@ node_ref::operator<(const node_ref& other) const { if (this->device != other.device) return this->device < other.device; + return this->node < other.node; } -// = node_ref& -node_ref::operator=(const node_ref &ref) +node_ref::operator=(const node_ref& other) { - device = ref.device; - node = ref.node; + device = other.device; + node = other.node; return *this; } @@ -92,53 +94,59 @@ node_ref::operator=(const node_ref &ref) BNode::BNode() - : fFd(-1), - fAttrFd(-1), - fCStatus(B_NO_INIT) + : + fFd(-1), + fAttrFd(-1), + fCStatus(B_NO_INIT) { } -BNode::BNode(const entry_ref *ref) - : fFd(-1), - fAttrFd(-1), - fCStatus(B_NO_INIT) +BNode::BNode(const entry_ref* ref) + : + fFd(-1), + fAttrFd(-1), + fCStatus(B_NO_INIT) { SetTo(ref); } -BNode::BNode(const BEntry *entry) - : fFd(-1), - fAttrFd(-1), - fCStatus(B_NO_INIT) +BNode::BNode(const BEntry* entry) + : + fFd(-1), + fAttrFd(-1), + fCStatus(B_NO_INIT) { SetTo(entry); } -BNode::BNode(const char *path) - : fFd(-1), - fAttrFd(-1), - fCStatus(B_NO_INIT) +BNode::BNode(const char* path) + : + fFd(-1), + fAttrFd(-1), + fCStatus(B_NO_INIT) { SetTo(path); } -BNode::BNode(const BDirectory *dir, const char *path) - : fFd(-1), - fAttrFd(-1), - fCStatus(B_NO_INIT) +BNode::BNode(const BDirectory* dir, const char* path) + : + fFd(-1), + fAttrFd(-1), + fCStatus(B_NO_INIT) { SetTo(dir, path); } -BNode::BNode(const BNode &node) - : fFd(-1), - fAttrFd(-1), - fCStatus(B_NO_INIT) +BNode::BNode(const BNode& node) + : + fFd(-1), + fAttrFd(-1), + fCStatus(B_NO_INIT) { *this = node; } @@ -158,37 +166,40 @@ BNode::InitCheck() const status_t -BNode::SetTo(const entry_ref *ref) +BNode::SetTo(const entry_ref* ref) { return _SetTo(ref, false); } status_t -BNode::SetTo(const BEntry *entry) +BNode::SetTo(const BEntry* entry) { - if (!entry) { + if (entry == NULL) { Unset(); return (fCStatus = B_BAD_VALUE); } + return _SetTo(entry->fDirFd, entry->fName, false); } status_t -BNode::SetTo(const char *path) +BNode::SetTo(const char* path) { return _SetTo(-1, path, false); } status_t -BNode::SetTo(const BDirectory *dir, const char *path) +BNode::SetTo(const BDirectory* dir, const char* path) { - if (!dir || !path || BPrivate::Storage::is_absolute_path(path)) { + if (dir == NULL || path == NULL + || BPrivate::Storage::is_absolute_path(path)) { Unset(); return (fCStatus = B_BAD_VALUE); } + return _SetTo(dir->fDirFd, path, false); } @@ -206,6 +217,7 @@ BNode::Lock() { if (fCStatus != B_OK) return fCStatus; + return _kern_lock_node(fFd); } @@ -215,6 +227,7 @@ BNode::Unlock() { if (fCStatus != B_OK) return fCStatus; + return _kern_unlock_node(fFd); } @@ -227,56 +240,61 @@ BNode::Sync() ssize_t -BNode::WriteAttr(const char *attr, type_code type, off_t offset, - const void *buffer, size_t len) +BNode::WriteAttr(const char* attr, type_code type, off_t offset, + const void* buffer, size_t length) { if (fCStatus != B_OK) return B_FILE_ERROR; - if (!attr || !buffer) + + if (attr == NULL || buffer == NULL) return B_BAD_VALUE; - ssize_t result = fs_write_attr(fFd, attr, type, offset, buffer, len); + ssize_t result = fs_write_attr(fFd, attr, type, offset, buffer, length); + return result < 0 ? errno : result; } ssize_t -BNode::ReadAttr(const char *attr, type_code type, off_t offset, - void *buffer, size_t len) const +BNode::ReadAttr(const char* attr, type_code type, off_t offset, + void* buffer, size_t length) const { if (fCStatus != B_OK) return B_FILE_ERROR; - if (!attr || !buffer) + + if (attr == NULL || buffer == NULL) return B_BAD_VALUE; - ssize_t result = fs_read_attr(fFd, attr, type, offset, buffer, len ); + ssize_t result = fs_read_attr(fFd, attr, type, offset, buffer, length); + return result == -1 ? errno : result; } status_t -BNode::RemoveAttr(const char *name) +BNode::RemoveAttr(const char* name) { return fCStatus != B_OK ? B_FILE_ERROR : _kern_remove_attr(fFd, name); } status_t -BNode::RenameAttr(const char *oldname, const char *newname) +BNode::RenameAttr(const char* oldName, const char* newName) { if (fCStatus != B_OK) return B_FILE_ERROR; - return _kern_rename_attr(fFd, oldname, fFd, newname); + return _kern_rename_attr(fFd, oldName, fFd, newName); } status_t -BNode::GetAttrInfo(const char *name, struct attr_info *info) const +BNode::GetAttrInfo(const char* name, struct attr_info* info) const { if (fCStatus != B_OK) return B_FILE_ERROR; - if (!name || !info) + + if (name == NULL || info == NULL) return B_BAD_VALUE; return fs_stat_attr(fFd, name, info) < 0 ? errno : B_OK ; @@ -284,13 +302,16 @@ BNode::GetAttrInfo(const char *name, struct attr_info *info) const status_t -BNode::GetNextAttrName(char *buffer) +BNode::GetNextAttrName(char* buffer) { // We're allowed to assume buffer is at least // B_ATTR_NAME_LENGTH chars long, but NULLs // are not acceptable. + + // BeOS R5 crashed when passed NULL if (buffer == NULL) - return B_BAD_VALUE; // /new R5 crashed when passed NULL + return B_BAD_VALUE; + if (InitAttrDir() != B_OK) return B_FILE_ERROR; @@ -298,9 +319,12 @@ BNode::GetNextAttrName(char *buffer) ssize_t result = _kern_read_dir(fAttrFd, &entry, sizeof(entry), 1); if (result < 0) return result; + if (result == 0) return B_ENTRY_NOT_FOUND; + strlcpy(buffer, entry.d_name, B_ATTR_NAME_LENGTH); + return B_OK; } @@ -316,24 +340,25 @@ BNode::RewindAttrs() status_t -BNode::WriteAttrString(const char *name, const BString *data) +BNode::WriteAttrString(const char* name, const BString* data) { status_t error = (!name || !data) ? B_BAD_VALUE : B_OK; if (error == B_OK) { - int32 len = data->Length() + 1; + int32 length = data->Length() + 1; ssize_t sizeWritten = WriteAttr(name, B_STRING_TYPE, 0, data->String(), - len); - if (sizeWritten != len) + length); + if (sizeWritten != length) error = sizeWritten; } + return error; } status_t -BNode::ReadAttrString(const char *name, BString *result) const +BNode::ReadAttrString(const char* name, BString* result) const { - if (!name || !result) + if (name == NULL || result == NULL) return B_BAD_VALUE; attr_info info; @@ -344,8 +369,8 @@ BNode::ReadAttrString(const char *name, BString *result) const return error; // Lock the string's buffer so we can meddle with it - char *data = result->LockBuffer(info.size + 1); - if (!data) + char* data = result->LockBuffer(info.size + 1); + if (data == NULL) return B_NO_MEMORY; // Read the attribute @@ -353,7 +378,8 @@ BNode::ReadAttrString(const char *name, BString *result) const // Check for failure if (bytes < 0) { error = bytes; - bytes = 0; // In this instance, we simply clear the string + bytes = 0; + // In this instance, we simply clear the string } else error = B_OK; @@ -361,12 +387,13 @@ BNode::ReadAttrString(const char *name, BString *result) const // possible to read and write non-NULL-terminated strings) data[bytes] = 0; result->UnlockBuffer(); + return error; } BNode& -BNode::operator=(const BNode &node) +BNode::operator=(const BNode& node) { // No need to do any assignment if already equal if (*this == node) @@ -378,30 +405,35 @@ BNode::operator=(const BNode &node) // is not declared to be const (which IMO is retarded). fFd = _kern_dup(node.fFd); fCStatus = (fFd < 0) ? B_NO_INIT : B_OK ; + return *this; } bool -BNode::operator==(const BNode &node) const +BNode::operator==(const BNode& node) const { if (fCStatus == B_NO_INIT && node.InitCheck() == B_NO_INIT) return true; + if (fCStatus == B_OK && node.InitCheck() == B_OK) { // compare the node_refs node_ref ref1, ref2; if (GetNodeRef(&ref1) != B_OK) return false; + if (node.GetNodeRef(&ref2) != B_OK) return false; + return (ref1 == ref2); } + return false; } bool -BNode::operator!=(const BNode &node) const +BNode::operator!=(const BNode& node) const { return !(*this == node); } @@ -411,7 +443,9 @@ int BNode::Dup() { int fd = _kern_dup(fFd); - return (fd >= 0 ? fd : -1); // comply with R5 return value + + return (fd >= 0 ? fd : -1); + // comply with R5 return value } @@ -424,16 +458,40 @@ void BNode::_RudeNode5() { } void BNode::_RudeNode6() { } +/*! Sets the node's file descriptor. + + Used by each implementation (i.e. BNode, BFile, BDirectory, etc.) to set + the node's file descriptor. This allows each subclass to use the various + file-type specific system calls for opening file descriptors. + + \note This method calls close_fd() to close previously opened FDs. Thus + derived classes should take care to first call set_fd() and set + class specific resources freed in their close_fd() version + thereafter. + + \param fd the file descriptor this BNode should be set to (may be -1). + + \returns \c B_OK if everything went fine, or an error code if something + went wrong. +*/ status_t BNode::set_fd(int fd) { if (fFd != -1) close_fd(); + fFd = fd; + return B_OK; } +/*! Closes the node's file descriptor(s). + + To be implemented by subclasses to close the file descriptor using the + proper system call for the given file-type. This implementation calls + _kern_close(fFd) and also _kern_close(fAttrDir) if necessary. +*/ void BNode::close_fd() { @@ -448,6 +506,13 @@ BNode::close_fd() } +/*! Sets the BNode's status. + + To be used by derived classes instead of accessing the BNode's private + \c fCStatus member directly. + + \param newStatus the new value for the status variable. +*/ void BNode::set_status(status_t newStatus) { @@ -455,10 +520,36 @@ BNode::set_status(status_t newStatus) } +/*! Initializes the BNode's file descriptor to the node referred to + by the given FD and path combo. + + \a path must either be \c NULL, an absolute or a relative path. + In the first case, \a fd must not be \c NULL; the node it refers to will + be opened. If absolute, \a fd is ignored. If relative and \a fd is >= 0, + it will be reckoned off the directory identified by \a fd, otherwise off + the current working directory. + + The method will first try to open the node with read and write permission. + If that fails due to a read-only FS or because the user has no write + permission for the node, it will re-try opening the node read-only. + + The \a fCStatus member will be set to the return value of this method. + + \param fd Either a directory FD or a value < 0. In the latter case \a path + must be specified. + \param path Either \a NULL in which case \a fd must be given, absolute, or + relative to the directory specified by \a fd (if given) or to the + current working directory. + \param traverse If the node identified by \a fd and \a path is a symlink + and \a traverse is \c true, the symlink will be resolved recursively. + + \returns \c B_OK if everything went fine, or an error code otherwise. +*/ status_t -BNode::_SetTo(int fd, const char *path, bool traverse) +BNode::_SetTo(int fd, const char* path, bool traverse) { Unset(); + status_t error = (fd >= 0 || path ? B_OK : B_BAD_VALUE); if (error == B_OK) { int traverseFlag = (traverse ? 0 : O_NOTRAVERSE); @@ -470,16 +561,33 @@ BNode::_SetTo(int fd, const char *path, bool traverse) if (fFd < 0) error = fFd; } + return fCStatus = error; } +/*! Initializes the BNode's file descriptor to the node referred to + by the given entry_ref. + + The method will first try to open the node with read and write permission. + If that fails due to a read-only FS or because the user has no write + permission for the node, it will re-try opening the node read-only. + + The \a fCStatus member will be set to the return value of this method. + + \param ref An entry_ref identifying the node to be opened. + \param traverse If the node identified by \a ref is a symlink and + \a traverse is \c true, the symlink will be resolved recursively. + + \returns \c B_OK if everything went fine, or an error code otherwise. +*/ status_t -BNode::_SetTo(const entry_ref *ref, bool traverse) +BNode::_SetTo(const entry_ref* ref, bool traverse) { Unset(); - status_t error = (ref ? B_OK : B_BAD_VALUE); - if (error == B_OK) { + + status_t result = (ref ? B_OK : B_BAD_VALUE); + if (result == B_OK) { int traverseFlag = (traverse ? 0 : O_NOTRAVERSE); fFd = _kern_open_entry_ref(ref->device, ref->directory, ref->name, O_RDWR | O_CLOEXEC | traverseFlag, 0); @@ -489,23 +597,41 @@ BNode::_SetTo(const entry_ref *ref, bool traverse) O_RDONLY | O_CLOEXEC | traverseFlag, 0); } if (fFd < 0) - error = fFd; + result = fFd; } - return fCStatus = error; + + return fCStatus = result; } +/*! Modifies a certain setting for this node based on \a what and the + corresponding value in \a st. + + Inherited from and called by BStatable. + + \param st a stat structure containing the value to be set. + \param what specifies what setting to be modified. + + \returns \c B_OK if everything went fine, or an error code otherwise. +*/ status_t -BNode::set_stat(struct stat &st, uint32 what) +BNode::set_stat(struct stat& stat, uint32 what) { if (fCStatus != B_OK) return B_FILE_ERROR; - return _kern_write_stat(fFd, NULL, false, &st, sizeof(struct stat), + return _kern_write_stat(fFd, NULL, false, &stat, sizeof(struct stat), what); } + +/*! Verifies that the BNode has been properly initialized, and then + (if necessary) opens the attribute directory on the node's file + descriptor, storing it in fAttrDir. + + \returns \c B_OK if everything went fine, or an error code otherwise. +*/ status_t BNode::InitAttrDir() { @@ -517,33 +643,35 @@ BNode::InitAttrDir() // set close on exec flag fcntl(fAttrFd, F_SETFD, FD_CLOEXEC); } + return fCStatus; } status_t -BNode::_GetStat(struct stat *st) const +BNode::_GetStat(struct stat* stat) const { return fCStatus != B_OK ? fCStatus - : _kern_read_stat(fFd, NULL, false, st, sizeof(struct stat)); + : _kern_read_stat(fFd, NULL, false, stat, sizeof(struct stat)); } status_t -BNode::_GetStat(struct stat_beos *st) const +BNode::_GetStat(struct stat_beos* stat) const { struct stat newStat; status_t error = _GetStat(&newStat); if (error != B_OK) return error; - convert_to_stat_beos(&newStat, st); + convert_to_stat_beos(&newStat, stat); + return B_OK; } -// #pragma mark - symbol versions +// #pragma mark - symbol versions #ifdef HAIKU_TARGET_PLATFORM_LIBBE_TEST diff --git a/src/kits/storage/NodeInfo.cpp b/src/kits/storage/NodeInfo.cpp index d0dca6cea2..246eab92b0 100644 --- a/src/kits/storage/NodeInfo.cpp +++ b/src/kits/storage/NodeInfo.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006, Haiku Inc. + * Copyright 2002-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -24,16 +24,21 @@ #include #include + using namespace std; + // attribute names #define NI_BEOS "BEOS" -static const char *kNITypeAttribute = NI_BEOS ":TYPE"; -static const char *kNIPreferredAppAttribute = NI_BEOS ":PREF_APP"; -static const char *kNIAppHintAttribute = NI_BEOS ":PPATH"; -static const char *kNIMiniIconAttribute = NI_BEOS ":M:STD_ICON"; -static const char *kNILargeIconAttribute = NI_BEOS ":L:STD_ICON"; -static const char *kNIIconAttribute = NI_BEOS ":ICON"; +static const char* kNITypeAttribute = NI_BEOS ":TYPE"; +static const char* kNIPreferredAppAttribute = NI_BEOS ":PREF_APP"; +static const char* kNIAppHintAttribute = NI_BEOS ":PPATH"; +static const char* kNIMiniIconAttribute = NI_BEOS ":M:STD_ICON"; +static const char* kNILargeIconAttribute = NI_BEOS ":L:STD_ICON"; +static const char* kNIIconAttribute = NI_BEOS ":ICON"; + + +// #pragma mark - BNodeInfo BNodeInfo::BNodeInfo() @@ -44,7 +49,7 @@ BNodeInfo::BNodeInfo() } -BNodeInfo::BNodeInfo(BNode *node) +BNodeInfo::BNodeInfo(BNode* node) : fNode(NULL), fCStatus(B_NO_INIT) @@ -60,7 +65,7 @@ BNodeInfo::~BNodeInfo() // Initializes the BNodeInfo to the supplied node. status_t -BNodeInfo::SetTo(BNode *node) +BNodeInfo::SetTo(BNode* node) { fNode = NULL; // check parameter @@ -82,166 +87,83 @@ BNodeInfo::InitCheck() const // Writes the MIME type of the node into type. status_t -BNodeInfo::GetType(char *type) const +BNodeInfo::GetType(char* type) const { // check parameter and initialization - status_t error = (type ? B_OK : B_BAD_VALUE); - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; + status_t result = (type ? B_OK : B_BAD_VALUE); + if (result == B_OK && InitCheck() != B_OK) + result = B_NO_INIT; // get the attribute info and check type and length of the attr contents attr_info attrInfo; - if (error == B_OK) - error = fNode->GetAttrInfo(kNITypeAttribute, &attrInfo); - if (error == B_OK && attrInfo.type != B_MIME_STRING_TYPE) - error = B_BAD_TYPE; - if (error == B_OK && attrInfo.size > B_MIME_TYPE_LENGTH) - error = B_BAD_DATA; + if (result == B_OK) + result = fNode->GetAttrInfo(kNITypeAttribute, &attrInfo); + if (result == B_OK && attrInfo.type != B_MIME_STRING_TYPE) + result = B_BAD_TYPE; + if (result == B_OK && attrInfo.size > B_MIME_TYPE_LENGTH) + result = B_BAD_DATA; // read the data - if (error == B_OK) { + if (result == B_OK) { ssize_t read = fNode->ReadAttr(kNITypeAttribute, attrInfo.type, 0, type, attrInfo.size); if (read < 0) - error = read; + result = read; else if (read != attrInfo.size) - error = B_ERROR; + result = B_ERROR; - if (error == B_OK) { + if (result == B_OK) { // attribute strings doesn't have to be null terminated type[min_c(attrInfo.size, B_MIME_TYPE_LENGTH - 1)] = '\0'; } } - return error; + return result; } // Sets the MIME type of the node. If type is NULL the BEOS:TYPE attribute is // removed instead. status_t -BNodeInfo::SetType(const char *type) +BNodeInfo::SetType(const char* type) { // check parameter and initialization - status_t error = B_OK; - if (error == B_OK && type && strlen(type) >= B_MIME_TYPE_LENGTH) - error = B_BAD_VALUE; - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; + status_t result = B_OK; + if (result == B_OK && type && strlen(type) >= B_MIME_TYPE_LENGTH) + result = B_BAD_VALUE; + if (result == B_OK && InitCheck() != B_OK) + result = B_NO_INIT; // write/remove the attribute - if (error == B_OK) { + if (result == B_OK) { if (type) { size_t toWrite = strlen(type) + 1; ssize_t written = fNode->WriteAttr(kNITypeAttribute, B_MIME_STRING_TYPE, 0, type, toWrite); if (written < 0) - error = written; + result = written; else if (written != (ssize_t)toWrite) - error = B_ERROR; + result = B_ERROR; } else - error = fNode->RemoveAttr(kNITypeAttribute); + result = fNode->RemoveAttr(kNITypeAttribute); } - return error; + return result; } // Gets the icon of the node. status_t -BNodeInfo::GetIcon(BBitmap *icon, icon_size k) const +BNodeInfo::GetIcon(BBitmap* icon, icon_size which) const { const char* iconAttribute = kNIIconAttribute; const char* miniIconAttribute = kNIMiniIconAttribute; const char* largeIconAttribute = kNILargeIconAttribute; return BIconUtils::GetIcon(fNode, iconAttribute, miniIconAttribute, - largeIconAttribute, k, icon); - -// status_t error = B_OK; -// // set some icon size related variables -// const char *attribute = NULL; -// BRect bounds; -// uint32 attrType = 0; -// size_t attrSize = 0; -// switch (k) { -// case B_MINI_ICON: -// attribute = kNIMiniIconAttribute; -// bounds.Set(0, 0, 15, 15); -// attrType = B_MINI_ICON_TYPE; -// attrSize = 16 * 16; -// break; -// case B_LARGE_ICON: -// attribute = kNILargeIconAttribute; -// bounds.Set(0, 0, 31, 31); -// attrType = B_LARGE_ICON_TYPE; -// attrSize = 32 * 32; -// break; -// default: -// error = B_BAD_VALUE; -// break; -// } -// -// // check parameter and initialization -// if (error == B_OK -// && (!icon || icon->InitCheck() != B_OK || icon->Bounds() != bounds)) { -// error = B_BAD_VALUE; -// } -// if (error == B_OK && InitCheck() != B_OK) -// error = B_NO_INIT; -// -// // get the attribute info and check type and size of the attr contents -// attr_info attrInfo; -// if (error == B_OK) -// error = fNode->GetAttrInfo(attribute, &attrInfo); -// if (error == B_OK && attrInfo.type != attrType) -// error = B_BAD_TYPE; -// if (error == B_OK && attrInfo.size != attrSize) -// error = B_BAD_DATA; -// -// // read the attribute -// if (error == B_OK) { -// bool otherColorSpace = (icon->ColorSpace() != B_CMAP8); -// char *buffer = NULL; -// ssize_t read; -// if (otherColorSpace) { -// // other color space than stored in attribute -// buffer = new(nothrow) char[attrSize]; -// if (!buffer) -// error = B_NO_MEMORY; -// if (error == B_OK) { -// read = fNode->ReadAttr(attribute, attrType, 0, buffer, -// attrSize); -// } -// } else { -// read = fNode->ReadAttr(attribute, attrType, 0, icon->Bits(), -// attrSize); -// } -// if (error == B_OK) { -// if (read < 0) -// error = read; -// else if (read != attrInfo.size) -// error = B_ERROR; -// } -// if (otherColorSpace) { -// // other color space than stored in attribute -// if (error == B_OK) { -// error = icon->ImportBits(buffer, attrSize, B_ANY_BYTES_PER_ROW, -// 0, B_CMAP8); -// } -// delete[] buffer; -// } -// } -// return error; -} - - -// Sets the icon of the node. If icon is NULL, the attribute is removed -// instead. -status_t -BNodeInfo::SetIcon(const BBitmap *icon, icon_size k) -{ - status_t error = B_OK; + largeIconAttribute, which, icon); +#if 0 + status_t result = B_OK; // set some icon size related variables - const char *attribute = NULL; + const char* attribute = NULL; BRect bounds; uint32 attrType = 0; size_t attrSize = 0; @@ -259,46 +181,142 @@ BNodeInfo::SetIcon(const BBitmap *icon, icon_size k) attrSize = 32 * 32; break; default: - error = B_BAD_VALUE; + result = B_BAD_VALUE; break; } // check parameter and initialization - if (error == B_OK && icon - && (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) { - error = B_BAD_VALUE; + if (result == B_OK + && (icon == NULL || icon->InitCheck() != B_OK + || icon->Bounds() != bounds)) { + result = B_BAD_VALUE; } - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; + if (result == B_OK && InitCheck() != B_OK) + result = B_NO_INIT; + + // get the attribute info and check type and size of the attr contents + attr_info attrInfo; + if (result == B_OK) + result = fNode->GetAttrInfo(attribute, &attrInfo); + + if (result == B_OK && attrInfo.type != attrType) + result = B_BAD_TYPE; + + if (result == B_OK && attrInfo.size != attrSize) + result = B_BAD_DATA; + + // read the attribute + if (result == B_OK) { + bool otherColorSpace = (icon->ColorSpace() != B_CMAP8); + char *buffer = NULL; + ssize_t read; + if (otherColorSpace) { + // other color space than stored in attribute + buffer = new(nothrow) char[attrSize]; + if (!buffer) + result = B_NO_MEMORY; + if (result == B_OK) { + read = fNode->ReadAttr(attribute, attrType, 0, buffer, + attrSize); + } + } else { + read = fNode->ReadAttr(attribute, attrType, 0, icon->Bits(), + attrSize); + } + if (result == B_OK) { + if (read < 0) + result = read; + else if (read != attrInfo.size) + result = B_ERROR; + } + if (otherColorSpace) { + // other color space than stored in attribute + if (result == B_OK) { + result = icon->ImportBits(buffer, attrSize, B_ANY_BYTES_PER_ROW, + 0, B_CMAP8); + } + delete[] buffer; + } + } + + return result; +#endif +} + + +// Sets the icon of the node. If icon is NULL, the attribute is removed +// instead. +status_t +BNodeInfo::SetIcon(const BBitmap* icon, icon_size which) +{ + status_t result = B_OK; + + // set some icon size related variables + const char* attribute = NULL; + BRect bounds; + uint32 attrType = 0; + size_t attrSize = 0; + + switch (which) { + case B_MINI_ICON: + attribute = kNIMiniIconAttribute; + bounds.Set(0, 0, 15, 15); + attrType = B_MINI_ICON_TYPE; + attrSize = 16 * 16; + break; + + case B_LARGE_ICON: + attribute = kNILargeIconAttribute; + bounds.Set(0, 0, 31, 31); + attrType = B_LARGE_ICON_TYPE; + attrSize = 32 * 32; + break; + + default: + result = B_BAD_VALUE; + break; + } + + // check parameter and initialization + if (result == B_OK && icon != NULL + && (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) { + result = B_BAD_VALUE; + } + if (result == B_OK && InitCheck() != B_OK) + result = B_NO_INIT; // write/remove the attribute - if (error == B_OK) { - if (icon) { + if (result == B_OK) { + if (icon != NULL) { bool otherColorSpace = (icon->ColorSpace() != B_CMAP8); ssize_t written = 0; if (otherColorSpace) { BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_CMAP8); - error = bitmap.InitCheck(); - if (error == B_OK) - error = bitmap.ImportBits(icon); - if (error == B_OK) { + result = bitmap.InitCheck(); + if (result == B_OK) + result = bitmap.ImportBits(icon); + + if (result == B_OK) { written = fNode->WriteAttr(attribute, attrType, 0, - bitmap.Bits(), attrSize); + bitmap.Bits(), attrSize); } } else { written = fNode->WriteAttr(attribute, attrType, 0, - icon->Bits(), attrSize); + icon->Bits(), attrSize); } - if (error == B_OK) { + if (result == B_OK) { if (written < 0) - error = written; + result = written; else if (written != (ssize_t)attrSize) - error = B_ERROR; + result = B_ERROR; } - } else // no icon given => remove - error = fNode->RemoveAttr(attribute); + } else { + // no icon given => remove + result = fNode->RemoveAttr(attribute); + } } - return error; + + return result; } @@ -307,7 +325,7 @@ status_t BNodeInfo::GetIcon(uint8** data, size_t* size, type_code* type) const { // check params - if (!data || !size || !type) + if (data == NULL || size == NULL || type == NULL) return B_BAD_VALUE; // check initialization @@ -353,183 +371,190 @@ BNodeInfo::SetIcon(const uint8* data, size_t size) if (InitCheck() != B_OK) return B_NO_INIT; - status_t error = B_OK; + status_t result = B_OK; // write/remove the attribute if (data && size > 0) { ssize_t written = fNode->WriteAttr(kNIIconAttribute, - B_VECTOR_ICON_TYPE, - 0, data, size); + B_VECTOR_ICON_TYPE, 0, data, size); if (written < 0) - error = (status_t)written; + result = (status_t)written; else if (written != (ssize_t)size) - error = B_ERROR; + result = B_ERROR; } else { // no icon given => remove - error = fNode->RemoveAttr(kNIIconAttribute); + result = fNode->RemoveAttr(kNIIconAttribute); } - return error; + return result; } // Gets the preferred application of the node. status_t -BNodeInfo::GetPreferredApp(char *signature, app_verb verb) const +BNodeInfo::GetPreferredApp(char* signature, app_verb verb) const { // check parameter and initialization - status_t error = (signature && verb == B_OPEN ? B_OK : B_BAD_VALUE); - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; + status_t result = (signature && verb == B_OPEN ? B_OK : B_BAD_VALUE); + if (result == B_OK && InitCheck() != B_OK) + result = B_NO_INIT; // get the attribute info and check type and length of the attr contents attr_info attrInfo; - if (error == B_OK) - error = fNode->GetAttrInfo(kNIPreferredAppAttribute, &attrInfo); - if (error == B_OK && attrInfo.type != B_MIME_STRING_TYPE) - error = B_BAD_TYPE; - if (error == B_OK && attrInfo.size > B_MIME_TYPE_LENGTH) - error = B_BAD_DATA; + if (result == B_OK) + result = fNode->GetAttrInfo(kNIPreferredAppAttribute, &attrInfo); + + if (result == B_OK && attrInfo.type != B_MIME_STRING_TYPE) + result = B_BAD_TYPE; + + if (result == B_OK && attrInfo.size > B_MIME_TYPE_LENGTH) + result = B_BAD_DATA; // read the data - if (error == B_OK) { + if (result == B_OK) { ssize_t read = fNode->ReadAttr(kNIPreferredAppAttribute, attrInfo.type, - 0, signature, attrInfo.size); + 0, signature, attrInfo.size); if (read < 0) - error = read; + result = read; else if (read != attrInfo.size) - error = B_ERROR; + result = B_ERROR; - if (error == B_OK) { + if (result == B_OK) { // attribute strings doesn't have to be null terminated signature[min_c(attrInfo.size, B_MIME_TYPE_LENGTH - 1)] = '\0'; } } - return error; + + return result; } // Sets the preferred application of the node. If signature is NULL, the // "BEOS:PREF_APP" attribute is removed instead. status_t -BNodeInfo::SetPreferredApp(const char *signature, app_verb verb) +BNodeInfo::SetPreferredApp(const char* signature, app_verb verb) { // check parameters and initialization - status_t error = (verb == B_OPEN ? B_OK : B_BAD_VALUE); - if (error == B_OK && signature && strlen(signature) >= B_MIME_TYPE_LENGTH) - error = B_BAD_VALUE; - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; + status_t result = (verb == B_OPEN ? B_OK : B_BAD_VALUE); + if (result == B_OK && signature && strlen(signature) >= B_MIME_TYPE_LENGTH) + result = B_BAD_VALUE; + + if (result == B_OK && InitCheck() != B_OK) + result = B_NO_INIT; // write/remove the attribute - if (error == B_OK) { + if (result == B_OK) { if (signature) { size_t toWrite = strlen(signature) + 1; ssize_t written = fNode->WriteAttr(kNIPreferredAppAttribute, - B_MIME_STRING_TYPE, 0, - signature, toWrite); + B_MIME_STRING_TYPE, 0, signature, toWrite); if (written < 0) - error = written; + result = written; else if (written != (ssize_t)toWrite) - error = B_ERROR; + result = B_ERROR; } else - error = fNode->RemoveAttr(kNIPreferredAppAttribute); + result = fNode->RemoveAttr(kNIPreferredAppAttribute); } - return error; + + return result; } // Fills out ref with a pointer to a hint about what application will open // this node. status_t -BNodeInfo::GetAppHint(entry_ref *ref) const +BNodeInfo::GetAppHint(entry_ref* ref) const { // check parameter and initialization - status_t error = (ref ? B_OK : B_BAD_VALUE); - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; + status_t result = (ref ? B_OK : B_BAD_VALUE); + if (result == B_OK && InitCheck() != B_OK) + result = B_NO_INIT; // get the attribute info and check type and length of the attr contents attr_info attrInfo; - if (error == B_OK) - error = fNode->GetAttrInfo(kNIAppHintAttribute, &attrInfo); + if (result == B_OK) + result = fNode->GetAttrInfo(kNIAppHintAttribute, &attrInfo); + // NOTE: The attribute type should be B_STRING_TYPE, but R5 uses // B_MIME_STRING_TYPE. - if (error == B_OK && attrInfo.type != B_MIME_STRING_TYPE) - error = B_BAD_TYPE; - if (error == B_OK && attrInfo.size > B_PATH_NAME_LENGTH) - error = B_BAD_DATA; + if (result == B_OK && attrInfo.type != B_MIME_STRING_TYPE) + result = B_BAD_TYPE; + + if (result == B_OK && attrInfo.size > B_PATH_NAME_LENGTH) + result = B_BAD_DATA; // read the data - if (error == B_OK) { + if (result == B_OK) { char path[B_PATH_NAME_LENGTH]; ssize_t read = fNode->ReadAttr(kNIAppHintAttribute, attrInfo.type, 0, - path, attrInfo.size); + path, attrInfo.size); if (read < 0) - error = read; + result = read; else if (read != attrInfo.size) - error = B_ERROR; + result = B_ERROR; + // get the entry_ref for the path - if (error == B_OK) { + if (result == B_OK) { // attribute strings doesn't have to be null terminated path[min_c(attrInfo.size, B_PATH_NAME_LENGTH - 1)] = '\0'; - error = get_ref_for_path(path, ref); + result = get_ref_for_path(path, ref); } } - return error; + + return result; } // Sets the app hint of the node. If ref is NULL, the "BEOS:PPATH" attribute // is removed instead. status_t -BNodeInfo::SetAppHint(const entry_ref *ref) +BNodeInfo::SetAppHint(const entry_ref* ref) { // check parameter and initialization - status_t error = B_OK; - if (error == B_OK && InitCheck() != B_OK) - error = B_NO_INIT; + if (InitCheck() != B_OK) + return B_NO_INIT; - // write/remove the attribute - if (error == B_OK) { - if (ref) { - BPath path; - error = path.SetTo(ref); - if (error == B_OK) { - size_t toWrite = strlen(path.Path()) + 1; - ssize_t written = fNode->WriteAttr(kNIAppHintAttribute, - B_MIME_STRING_TYPE, 0, - path.Path(), toWrite); - if (written < 0) - error = written; - else if (written != (ssize_t)toWrite) - error = B_ERROR; - } - } else - error = fNode->RemoveAttr(kNIAppHintAttribute); - } - return error; + status_t result = B_OK; + if (ref != NULL) { + // write/remove the attribute + BPath path; + result = path.SetTo(ref); + if (result == B_OK) { + size_t toWrite = strlen(path.Path()) + 1; + ssize_t written = fNode->WriteAttr(kNIAppHintAttribute, + B_MIME_STRING_TYPE, 0, path.Path(), toWrite); + if (written < 0) + result = written; + else if (written != (ssize_t)toWrite) + result = B_ERROR; + } + } else + result = fNode->RemoveAttr(kNIAppHintAttribute); + + return result; } // Gets the icon displayed by Tracker for the icon. status_t -BNodeInfo::GetTrackerIcon(BBitmap *icon, icon_size iconSize) const +BNodeInfo::GetTrackerIcon(BBitmap* icon, icon_size which) const { - if (!icon) + if (icon == NULL) return B_BAD_VALUE; // set some icon size related variables BRect bounds; - switch (iconSize) { + switch (which) { case B_MINI_ICON: bounds.Set(0, 0, 15, 15); break; + case B_LARGE_ICON: bounds.Set(0, 0, 31, 31); break; + default: -// error = B_BAD_VALUE; +// result = B_BAD_VALUE; // NOTE: added to be less strict and support scaled icons bounds = icon->Bounds(); break; @@ -543,20 +568,20 @@ BNodeInfo::GetTrackerIcon(BBitmap *icon, icon_size iconSize) const return B_NO_INIT; // Ask GetIcon() first. - if (GetIcon(icon, iconSize) == B_OK) + if (GetIcon(icon, which) == B_OK) return B_OK; // If not successful, see if the node has a type available at all. // If no type is available, use one of the standard types. - status_t error = B_OK; + status_t result = B_OK; char mimeString[B_MIME_TYPE_LENGTH]; if (GetType(mimeString) != B_OK) { // Get the icon from a mime type... BMimeType type; - + struct stat stat; - error = fNode->GetStat(&stat); - if (error == B_OK) { + result = fNode->GetStat(&stat); + if (result == B_OK) { // no type available -- get the icon for the appropriate type // (file/dir/etc.) if (S_ISREG(stat.st_mode)) { @@ -581,7 +606,7 @@ BNodeInfo::GetTrackerIcon(BBitmap *icon, icon_size iconSize) const type.SetTo(B_FILE_MIME_TYPE); } - return type.GetIcon(icon, iconSize); + return type.GetIcon(icon, which); } else { // We know the mimetype of the node. bool success = false; @@ -591,7 +616,7 @@ BNodeInfo::GetTrackerIcon(BBitmap *icon, icon_size iconSize) const char signature[B_MIME_TYPE_LENGTH]; if (GetPreferredApp(signature) == B_OK) { BMimeType type(signature); - success = type.GetIconForType(mimeString, icon, iconSize) == B_OK; + success = type.GetIconForType(mimeString, icon, which) == B_OK; } // ToDo: Confirm Tracker asks preferred app icons before asking @@ -604,13 +629,13 @@ BNodeInfo::GetTrackerIcon(BBitmap *icon, icon_size iconSize) const // type. if (!success && nodeType.GetPreferredApp(signature) == B_OK) { BMimeType type(signature); - success = type.GetIconForType(mimeString, icon, iconSize) == B_OK; + success = type.GetIconForType(mimeString, icon, which) == B_OK; } // Ask the MIME database whether there is an icon for the node's file // type. if (!success) - success = nodeType.GetIcon(icon, iconSize) == B_OK; + success = nodeType.GetIcon(icon, which) == B_OK; // Get the super type if still no success. BMimeType superType; @@ -621,13 +646,13 @@ BNodeInfo::GetTrackerIcon(BBitmap *icon, icon_size iconSize) const if (superType.GetPreferredApp(signature) == B_OK) { BMimeType type(signature); success = type.GetIconForType(superType.Type(), icon, - iconSize) == B_OK; + which) == B_OK; } // Get the icon of the super type itself. if (!success) - success = superType.GetIcon(icon, iconSize) == B_OK; + success = superType.GetIcon(icon, which) == B_OK; } - + if (success) return B_OK; } @@ -638,25 +663,26 @@ BNodeInfo::GetTrackerIcon(BBitmap *icon, icon_size iconSize) const // Gets the icon displayed by Tracker for the node referred to by ref. status_t -BNodeInfo::GetTrackerIcon(const entry_ref *ref, BBitmap *icon, icon_size iconSize) +BNodeInfo::GetTrackerIcon(const entry_ref* ref, BBitmap* icon, icon_size which) { // check ref param - status_t error = (ref ? B_OK : B_BAD_VALUE); + status_t result = (ref ? B_OK : B_BAD_VALUE); // init a BNode BNode node; - if (error == B_OK) - error = node.SetTo(ref); + if (result == B_OK) + result = node.SetTo(ref); // init a BNodeInfo BNodeInfo nodeInfo; - if (error == B_OK) - error = nodeInfo.SetTo(&node); + if (result == B_OK) + result = nodeInfo.SetTo(&node); // let the non-static GetTrackerIcon() do the dirty work - if (error == B_OK) - error = nodeInfo.GetTrackerIcon(icon, iconSize); - return error; + if (result == B_OK) + result = nodeInfo.GetTrackerIcon(icon, which); + + return result; } @@ -665,7 +691,7 @@ BNodeInfo::GetTrackerIcon(const entry_ref *ref, BBitmap *icon, icon_size iconSiz extern "C" status_t GetTrackerIcon__9BNodeInfoP9entry_refP7BBitmap9icon_size( - BNodeInfo *nodeInfo, entry_ref* ref, + BNodeInfo* nodeInfo, entry_ref* ref, BBitmap* bitmap, icon_size iconSize) { // NOTE: nodeInfo is ignored - maybe that's wrong! @@ -673,27 +699,14 @@ GetTrackerIcon__9BNodeInfoP9entry_refP7BBitmap9icon_size( } -void -BNodeInfo::_ReservedNodeInfo1() -{ -} - - -void -BNodeInfo::_ReservedNodeInfo2() -{ -} - - -void -BNodeInfo::_ReservedNodeInfo3() -{ -} +void BNodeInfo::_ReservedNodeInfo1() {} +void BNodeInfo::_ReservedNodeInfo2() {} +void BNodeInfo::_ReservedNodeInfo3() {} // Assignment operator is declared private to prevent it from being created // automatically by the compiler. -BNodeInfo & +BNodeInfo& BNodeInfo::operator=(const BNodeInfo &nodeInfo) { return *this; @@ -707,15 +720,12 @@ BNodeInfo::BNodeInfo(const BNodeInfo &) } -// #pragma mark - - - namespace BPrivate { // Private method used by Tracker. This should be moved to the Tracker // source. extern bool -CheckNodeIconHintPrivate(const BNode *node, bool checkMiniIconOnly) +CheckNodeIconHintPrivate(const BNode* node, bool checkMiniIconOnly) { attr_info info; if (node->GetAttrInfo(kNIMiniIconAttribute, &info) != B_OK && checkMiniIconOnly) diff --git a/src/kits/storage/NodeMonitor.cpp b/src/kits/storage/NodeMonitor.cpp index 48c8cf1336..24d7657d3d 100644 --- a/src/kits/storage/NodeMonitor.cpp +++ b/src/kits/storage/NodeMonitor.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2010, Haiku. + * Copyright 2001-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -39,8 +39,8 @@ watch_volume(dev_t volume, uint32 flags, BMessenger target) status_t -watch_volume(dev_t volume, uint32 flags, const BHandler *handler, - const BLooper *looper) +watch_volume(dev_t volume, uint32 flags, const BHandler* handler, + const BLooper* looper) { return watch_volume(volume, flags, BMessenger(handler, looper)); } @@ -48,7 +48,7 @@ watch_volume(dev_t volume, uint32 flags, const BHandler *handler, // Subscribes or unsubscribes a target to node and/or mount watching. status_t -watch_node(const node_ref *node, uint32 flags, BMessenger target) +watch_node(const node_ref* node, uint32 flags, BMessenger target) { if (!target.IsValid()) return B_BAD_VALUE; @@ -92,8 +92,8 @@ watch_node(const node_ref *node, uint32 flags, BMessenger target) // Subscribes or unsubscribes a handler or looper to node and/or mount // watching. status_t -watch_node(const node_ref *node, uint32 flags, const BHandler *handler, - const BLooper *looper) +watch_node(const node_ref* node, uint32 flags, const BHandler* handler, + const BLooper* looper) { return watch_node(node, flags, BMessenger(handler, looper)); } @@ -116,7 +116,7 @@ stop_watching(BMessenger target) // Unsubscribes a target from node and mount monitoring. status_t -stop_watching(const BHandler *handler, const BLooper *looper) +stop_watching(const BHandler* handler, const BLooper* looper) { return stop_watching(BMessenger(handler, looper)); } diff --git a/src/kits/storage/Path.cpp b/src/kits/storage/Path.cpp index 442462a935..3c47d4f5bf 100644 --- a/src/kits/storage/Path.cpp +++ b/src/kits/storage/Path.cpp @@ -22,6 +22,7 @@ #include "storage_support.h" + using namespace std; @@ -424,7 +425,7 @@ BPath::Flatten(void* buffer, ssize_t size) const if (buffer == NULL) return B_BAD_VALUE; - // ToDo: Re-implement for performance reasons: Don't call FlattenedSize(). + // ToDo: Reimplement for performance reasons: Don't call FlattenedSize(). ssize_t flattenedSize = FlattenedSize(); if (flattenedSize < 0) return flattenedSize; @@ -497,7 +498,17 @@ void BPath::_WarPath2() {} void BPath::_WarPath3() {} -// Sets the supplied path. +/*! Sets the supplied path. + + The path is copied, if \a path is \c NULL the path of the object is set to + \c NULL as well. The old path is deleted. + + \param path the path to be set + + \returns A status code. + \retval B_OK Everything went fine. + \retval B_NO_MEMORY Insufficient memory. +*/ status_t BPath::_SetPath(const char* path) { @@ -519,7 +530,19 @@ BPath::_SetPath(const char* path) } -// Checks a path to see if normalization is required. +/*! Checks a path to see if normalization is required. + + The following items require normalization: + - Relative pathnames (after concatenation; e.g. "boot/ltj") + - The presence of "." or ".." ("/boot/ltj/../ltj/./gwar") + - Redundant slashes ("/boot//ltj") + - A trailing slash ("/boot/ltj/") + + \param _error A pointer to an error variable that will be set if the input + is not a valid path. + + \return \c true if \a path requires normalization, \c false otherwise. +*/ bool BPath::_MustNormalize(const char* path, status_t* _error) { diff --git a/src/kits/storage/Query.cpp b/src/kits/storage/Query.cpp index 64187511e7..20244f61f1 100644 --- a/src/kits/storage/Query.cpp +++ b/src/kits/storage/Query.cpp @@ -399,7 +399,10 @@ BQuery::CountEntries() } -// Gets whether Fetch() has already been called on this object. +/*! Gets whether Fetch() has already been called on this object. + + \return \c true, if Fetch() was already called, \c false otherwise. +*/ bool BQuery::_HasFetched() const { @@ -407,7 +410,27 @@ BQuery::_HasFetched() const } -// Pushes a node onto the predicate stack. +/*! Pushes a node onto the predicate stack. + + If the stack has not been allocate until this time, this method does + allocate it. + + If the supplied node is \c NULL, it is assumed that there was not enough + memory to allocate the node and thus \c B_NO_MEMORY is returned. + + In case the method fails, the caller retains the ownership of the supplied + node and thus is responsible for deleting it, if \a deleteOnError is + \c false. If it is \c true, the node is deleted, if an error occurs. + + \param node The node to push. + \param deleteOnError Whether or not to delete the node if an error occurs. + + \return A status code. + \retval B_OK Everything went fine. + \retval B_NO_MEMORY \a node was \c NULL or there was insufficient memory to + allocate the predicate stack or push the node. + \retval B_NOT_ALLOWED _PushNode() was called after Fetch(). +*/ status_t BQuery::_PushNode(QueryNode* node, bool deleteOnError) { @@ -428,7 +451,16 @@ BQuery::_PushNode(QueryNode* node, bool deleteOnError) } -// Helper method to set the predicate. +/*! Helper method to set the predicate. + + Does not check whether Fetch() has already been invoked. + + \param expression The predicate string to set. + + \return A status code. + \retval B_OK Everything went fine. + \retval B_NO_MEMORY There was insufficient memory to store the predicate. +*/ status_t BQuery::_SetPredicate(const char* expression) { @@ -448,7 +480,17 @@ BQuery::_SetPredicate(const char* expression) } -// Evaluates the predicate stack. +/*! Evaluates the predicate stack. + + The method does nothing (and returns \c B_OK), if the stack is \c NULL. + If the stack is not \c null and Fetch() has already been called, this + method fails. + + \return A status code. + \retval B_OK Everything went fine. + \retval B_NO_MEMORY There was insufficient memory. + \retval B_NOT_ALLOWED _EvaluateStack() was called after Fetch(). +*/ status_t BQuery::_EvaluateStack() { @@ -473,6 +515,10 @@ BQuery::_EvaluateStack() } +/*! Fills out \a parsedPredicate with a parsed predicate string. + + \param parsedPredicate The predicate string to fill out. +*/ void BQuery::_ParseDates(BString& parsedPredicate) { diff --git a/src/kits/storage/Statable.cpp b/src/kits/storage/Statable.cpp index 6c7f44b4da..2f4f78555b 100644 --- a/src/kits/storage/Statable.cpp +++ b/src/kits/storage/Statable.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2014 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -27,9 +27,9 @@ public: { } - status_t GetStatBeOS(struct stat_beos* st) + status_t GetStatBeOS(struct stat_beos* stat) { - return fObject->_GetStat(st); + return fObject->_GetStat(stat); } private: @@ -48,9 +48,9 @@ BStatable::~BStatable() bool BStatable::IsFile() const { - struct stat statData; - if (GetStat(&statData) == B_OK) - return S_ISREG(statData.st_mode); + struct stat stat; + if (GetStat(&stat) == B_OK) + return S_ISREG(stat.st_mode); else return false; } @@ -60,9 +60,9 @@ BStatable::IsFile() const bool BStatable::IsDirectory() const { - struct stat statData; - if (GetStat(&statData) == B_OK) - return S_ISDIR(statData.st_mode); + struct stat stat; + if (GetStat(&stat) == B_OK) + return S_ISDIR(stat.st_mode); else return false; } @@ -72,9 +72,9 @@ BStatable::IsDirectory() const bool BStatable::IsSymLink() const { - struct stat statData; - if (GetStat(&statData) == B_OK) - return S_ISLNK(statData.st_mode); + struct stat stat; + if (GetStat(&stat) == B_OK) + return S_ISLNK(stat.st_mode); else return false; } @@ -82,31 +82,37 @@ BStatable::IsSymLink() const // Fills out ref with the node_ref of the node. status_t -BStatable::GetNodeRef(node_ref *ref) const +BStatable::GetNodeRef(node_ref* ref) const { - status_t error = (ref ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) { - ref->device = statData.st_dev; - ref->node = statData.st_ino; + status_t result = (ref ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) { + ref->device = stat.st_dev; + ref->node = stat.st_ino; } - return error; + + return result; } // Fills out the node's UID into owner. status_t -BStatable::GetOwner(uid_t *owner) const +BStatable::GetOwner(uid_t* owner) const { - status_t error = (owner ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - *owner = statData.st_uid; - return error; + status_t result = (owner ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + *owner = stat.st_uid; + + return result; } @@ -114,23 +120,27 @@ BStatable::GetOwner(uid_t *owner) const status_t BStatable::SetOwner(uid_t owner) { - struct stat statData; - statData.st_uid = owner; - return set_stat(statData, B_STAT_UID); + struct stat stat; + stat.st_uid = owner; + + return set_stat(stat, B_STAT_UID); } // Fills out the node's GID into group. status_t -BStatable::GetGroup(gid_t *group) const +BStatable::GetGroup(gid_t* group) const { - status_t error = (group ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - *group = statData.st_gid; - return error; + status_t result = (group ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + *group = stat.st_gid; + + return result; } @@ -138,63 +148,74 @@ BStatable::GetGroup(gid_t *group) const status_t BStatable::SetGroup(gid_t group) { - struct stat statData; - statData.st_gid = group; - return set_stat(statData, B_STAT_GID); + struct stat stat; + stat.st_gid = group; + + return set_stat(stat, B_STAT_GID); } -// Fills out perms with the node's permissions. +// Fills out permissions with the node's permissions. status_t -BStatable::GetPermissions(mode_t *perms) const +BStatable::GetPermissions(mode_t* permissions) const { - status_t error = (perms ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - *perms = (statData.st_mode & S_IUMSK); - return error; + status_t result = (permissions ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + *permissions = (stat.st_mode & S_IUMSK); + + return result; } -// Sets the node's permissions to perms. +// Sets the node's permissions to permissions. status_t -BStatable::SetPermissions(mode_t perms) +BStatable::SetPermissions(mode_t permissions) { - struct stat statData; + struct stat stat; // the FS should do the correct masking -- only the S_IUMSK part is // modifiable - statData.st_mode = perms; - return set_stat(statData, B_STAT_MODE); + stat.st_mode = permissions; + + return set_stat(stat, B_STAT_MODE); } // Fills out the size of the node's data (not counting attributes) into size. status_t -BStatable::GetSize(off_t *size) const +BStatable::GetSize(off_t* size) const { - status_t error = (size ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - *size = statData.st_size; - return error; + status_t result = (size ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + *size = stat.st_size; + + return result; } // Fills out mtime with the last modification time of the node. status_t -BStatable::GetModificationTime(time_t *mtime) const +BStatable::GetModificationTime(time_t* mtime) const { - status_t error = (mtime ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - *mtime = statData.st_mtime; - return error; + status_t result = (mtime ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + *mtime = stat.st_mtime; + + return result; } @@ -202,23 +223,27 @@ BStatable::GetModificationTime(time_t *mtime) const status_t BStatable::SetModificationTime(time_t mtime) { - struct stat statData; - statData.st_mtime = mtime; - return set_stat(statData, B_STAT_MODIFICATION_TIME); + struct stat stat; + stat.st_mtime = mtime; + + return set_stat(stat, B_STAT_MODIFICATION_TIME); } // Fills out ctime with the creation time of the node status_t -BStatable::GetCreationTime(time_t *ctime) const +BStatable::GetCreationTime(time_t* ctime) const { - status_t error = (ctime ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - *ctime = statData.st_crtime; - return error; + status_t result = (ctime ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + *ctime = stat.st_crtime; + + return result; } @@ -226,23 +251,27 @@ BStatable::GetCreationTime(time_t *ctime) const status_t BStatable::SetCreationTime(time_t ctime) { - struct stat statData; - statData.st_crtime = ctime; - return set_stat(statData, B_STAT_CREATION_TIME); + struct stat stat; + stat.st_crtime = ctime; + + return set_stat(stat, B_STAT_CREATION_TIME); } // Fills out atime with the access time of the node. status_t -BStatable::GetAccessTime(time_t *atime) const +BStatable::GetAccessTime(time_t* atime) const { - status_t error = (atime ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - *atime = statData.st_atime; - return error; + status_t result = (atime ? B_OK : B_BAD_VALUE); + struct stat stat; + + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + *atime = stat.st_atime; + + return result; } @@ -250,41 +279,45 @@ BStatable::GetAccessTime(time_t *atime) const status_t BStatable::SetAccessTime(time_t atime) { - struct stat statData; - statData.st_atime = atime; - return set_stat(statData, B_STAT_ACCESS_TIME); + struct stat stat; + stat.st_atime = atime; + + return set_stat(stat, B_STAT_ACCESS_TIME); } // Fills out vol with the the volume that the node lives on. status_t -BStatable::GetVolume(BVolume *vol) const +BStatable::GetVolume(BVolume* volume) const { - status_t error = (vol ? B_OK : B_BAD_VALUE); - struct stat statData; - if (error == B_OK) - error = GetStat(&statData); - if (error == B_OK) - error = vol->SetTo(statData.st_dev); - return error; + status_t result = (volume ? B_OK : B_BAD_VALUE); + struct stat stat; + if (result == B_OK) + result = GetStat(&stat); + + if (result == B_OK) + result = volume->SetTo(stat.st_dev); + + return result; } // _OhSoStatable1() -> GetStat() extern "C" status_t #if __GNUC__ == 2 -_OhSoStatable1__9BStatable(const BStatable *self, struct stat *st) +_OhSoStatable1__9BStatable(const BStatable* self, struct stat* stat) #else -_ZN9BStatable14_OhSoStatable1Ev(const BStatable *self, struct stat *st) +_ZN9BStatable14_OhSoStatable1Ev(const BStatable* self, struct stat* stat) #endif { // No Perform() method -- we have to use the old GetStat() method instead. struct stat_beos oldStat; - status_t error = BStatable::Private(self).GetStatBeOS(&oldStat); - if (error != B_OK) - return error; + status_t result = BStatable::Private(self).GetStatBeOS(&oldStat); + if (result != B_OK) + return result; + + convert_from_stat_beos(&oldStat, stat); - convert_from_stat_beos(&oldStat, st); return B_OK; } diff --git a/src/kits/storage/SymLink.cpp b/src/kits/storage/SymLink.cpp index fe3190b934..2b6b490ced 100644 --- a/src/kits/storage/SymLink.cpp +++ b/src/kits/storage/SymLink.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Haiku Inc. + * Copyright 2002-2009 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -31,16 +31,16 @@ BSymLink::BSymLink() // Creates a copy of the supplied BSymLink object. -BSymLink::BSymLink(const BSymLink &link) +BSymLink::BSymLink(const BSymLink& other) : - BNode(link) + BNode(other) { } // Creates a BSymLink object and initializes it to the symbolic link referred // to by the supplied entry_ref. -BSymLink::BSymLink(const entry_ref *ref) +BSymLink::BSymLink(const entry_ref* ref) : BNode(ref) { @@ -49,7 +49,7 @@ BSymLink::BSymLink(const entry_ref *ref) // Creates a BSymLink object and initializes it to the symbolic link referred // to by the supplied BEntry. -BSymLink::BSymLink(const BEntry *entry) +BSymLink::BSymLink(const BEntry* entry) : BNode(entry) { } @@ -57,7 +57,7 @@ BSymLink::BSymLink(const BEntry *entry) // Creates a BSymLink object and initializes it to the symbolic link referred // to by the supplied path name. -BSymLink::BSymLink(const char *path) +BSymLink::BSymLink(const char* path) : BNode(path) { @@ -66,7 +66,7 @@ BSymLink::BSymLink(const char *path) // Creates a BSymLink object and initializes it to the symbolic link referred // to by the supplied path name relative to the specified BDirectory. -BSymLink::BSymLink(const BDirectory *dir, const char *path) +BSymLink::BSymLink(const BDirectory* dir, const char* path) : BNode(dir, path) { @@ -81,7 +81,7 @@ BSymLink::~BSymLink() // Reads the contents of the symbolic link into a buffer. ssize_t -BSymLink::ReadLink(char *buffer, size_t size) +BSymLink::ReadLink(char* buffer, size_t size) { if (buffer == NULL) return B_BAD_VALUE; @@ -90,9 +90,9 @@ BSymLink::ReadLink(char *buffer, size_t size) return B_FILE_ERROR; size_t linkLen = size; - status_t error = _kern_read_link(get_fd(), NULL, buffer, &linkLen); - if (error < B_OK) - return error; + status_t result = _kern_read_link(get_fd(), NULL, buffer, &linkLen); + if (result < B_OK) + return result; // null-terminate if (linkLen >= size) @@ -107,7 +107,7 @@ BSymLink::ReadLink(char *buffer, size_t size) // Combines a directory path and the contents of this symbolic link to form an // absolute path. ssize_t -BSymLink::MakeLinkedPath(const char *dirPath, BPath *path) +BSymLink::MakeLinkedPath(const char* dirPath, BPath* path) { // BeOS seems to convert the dirPath to a BDirectory, which causes links // to be resolved. This means that the dirPath must exist! @@ -126,7 +126,7 @@ BSymLink::MakeLinkedPath(const char *dirPath, BPath *path) // Combines a directory path and the contents of this symbolic link to form an // absolute path. ssize_t -BSymLink::MakeLinkedPath(const BDirectory *dir, BPath *path) +BSymLink::MakeLinkedPath(const BDirectory* dir, BPath* path) { if (dir == NULL || path == NULL) return B_BAD_VALUE; @@ -168,7 +168,13 @@ void BSymLink::_MissingSymLink5() {} void BSymLink::_MissingSymLink6() {} -// Returns the file descriptor of the BSymLink. +/*! Returns the file descriptor of the BSymLink. + + This method should be used instead of accessing the private \c fFd member + of the BNode directly. + + \return The object's file descriptor, or -1 if not properly initialized. +*/ int BSymLink::get_fd() const { diff --git a/src/tests/kits/storage/MimeTypeTest.cpp b/src/tests/kits/storage/MimeTypeTest.cpp index 30d8e90746..319b321878 100644 --- a/src/tests/kits/storage/MimeTypeTest.cpp +++ b/src/tests/kits/storage/MimeTypeTest.cpp @@ -84,7 +84,7 @@ static const char *attrInfoField_Editable = "attr:editable"; // Descriptions static const char *testDescr = "Just a test, nothing more :-)"; static const char *testDescr2 = "Another amazing test string"; -static const char *longDescr = +static const char *longDescr = "This description is longer than B_MIME_TYPE_LENGTH, which is quite useful for certain things... " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" @@ -138,13 +138,13 @@ public: cout << "(Making a copy of your MIME database at '" + mimeDatabaseDir + "')" << endl; std::string cmd = std::string("copyattr -d -r -- ") + R5DatabaseDir + " " + mimeDatabaseDir; - ExecCommand(cmd.c_str()); + ExecCommand(cmd.c_str()); } else { fMimeDirExisted = true; if (BTestShell::GlobalBeVerbose()) cout << "(Using existing copy of MIME database in '" + mimeDatabaseDir + "')" << endl; } - } + } } virtual void tearDown() @@ -153,7 +153,7 @@ public: if (BTestShell::GlobalBeVerbose()) cout << "(Removing copy of MIME database in '" + mimeDatabaseDir + "')" << endl; std::string cmd = std::string("rm -rf ") + mimeDatabaseDir; - ExecCommand(cmd.c_str()); + ExecCommand(cmd.c_str()); } } @@ -161,7 +161,7 @@ public: { setUp(); CppUnit::TestSuite::run(result); - tearDown(); + tearDown(); } private: bool fMimeDirExisted; @@ -172,7 +172,7 @@ CppUnit::Test* MimeTypeTest::Suite() { MimeTypeTestSuite *suite = new MimeTypeTestSuite(); typedef CppUnit::TestCaller TC; - + // Tyler suite->addTest( new TC("BMimeType::Install/Delete Test", &MimeTypeTest::InstallDeleteTest) ); @@ -205,7 +205,7 @@ MimeTypeTest::Suite() { suite->addTest( new TC("BMimeType::Wildcard Apps Test", &MimeTypeTest::WildcardAppsTest) ); - // Ingo + // Ingo suite->addTest( new TC("BMimeType::Initialization Test", &MimeTypeTest::InitTest) ); suite->addTest( new TC("BMimeType::MIME String Test", @@ -222,10 +222,10 @@ MimeTypeTest::Suite() { &MimeTypeTest::SnifferRuleTest) ); suite->addTest( new TC("BMimeType::Sniffing Test", &MimeTypeTest::SniffingTest) ); - - + + return suite; -} +} // Handy comparison operators for BBitmaps. The size and color depth // are compared first, followed by the bitmap data. @@ -246,7 +246,7 @@ operator==(BBitmap &bmp1, BBitmap &bmp2) { // printf("i == %d\n", i); return false; } - } + } /* for (int i = 0; i < bmp1.Bounds().IntegerHeight(); i++) { for (int j = 0; j < bmp1.Bounds().IntegerWidth(); j++) { // printf("(%d, %d)", data1[(i * bmp1.BytesPerRow()) + j], data2[(i * bmp2.BytesPerRow()) + j]); @@ -274,7 +274,7 @@ operator!=(BBitmap &bmp1, BBitmap &bmp2) { bool operator==(BMessage &msg1, BMessage &msg2) { status_t err = B_OK; - + // For now I'm ignoring the what fields...I shall deal with that later :-) if (msg1.what != msg2.what) return false; @@ -285,14 +285,14 @@ operator==(BMessage &msg1, BMessage &msg2) { msg2.PrintToStream(); printf("----------------------------------------------------------------------\n"); */ - + // Check the counts of field names - int count1, count2; + int count1, count2; count1 = msg1.CountNames(B_ANY_TYPE); count2 = msg2.CountNames(B_ANY_TYPE); if (count1 != count2 && (count1 == 0 || count2 == 0)) return false; - + // Iterate over all the names in msg1 and check that the field // with the same name exists in msg2, is of the same type, and // contains identical data. @@ -300,28 +300,28 @@ operator==(BMessage &msg1, BMessage &msg2) { char *name; type_code typeFound1, typeFound2; int32 countFound1, countFound2; - + // Check type and count info - err = msg1.GetInfo(B_ANY_TYPE, i, &name, &typeFound1, &countFound1); - if (!err) + err = msg1.GetInfo(B_ANY_TYPE, i, &name, &typeFound1, &countFound1); + if (!err) err = msg2.GetInfo(name, &typeFound2, &countFound2); - if (!err) + if (!err) err = (typeFound1 == typeFound2 && countFound1 == countFound2 ? B_OK : B_ERROR); if (!err) { // Check all the data items for (int j = 0; j < countFound1; j++) { void *data1, *data2; ssize_t bytes1, bytes2; - + err = msg1.FindData(name, typeFound1, j, (const void**)&data1, &bytes1); - if (!err) + if (!err) err = msg2.FindData(name, typeFound2, j, (const void**)&data2, &bytes2); - if (!err) - err = (bytes1 == bytes2 && memcmp(data1, data2, bytes1) == 0 ? B_OK : B_ERROR); + if (!err) + err = (bytes1 == bytes2 && memcmp(data1, data2, bytes1) == 0 ? B_OK : B_ERROR); } } } - + return !err; } @@ -341,7 +341,7 @@ fill_bitmap(BBitmap &bmp, char value) { } // printf("\n"); } - + // Fills the bitmap data with the given character void fill_bitmap32(BBitmap &bmp, char r, char g, char b, char a) { @@ -357,7 +357,7 @@ fill_bitmap32(BBitmap &bmp, char r, char g, char b, char a) { // printf("\n"); } } - + // Dumps the size, colorspace, and first data byte // of the bitmap to stdout /*void @@ -368,18 +368,18 @@ dump_bitmap(BBitmap &bmp, char *name = "bmp") { case B_CMAP8: printf("B_CMAP8"); break; - + case B_RGB32: printf("B_RGB32"); break; - + case B_RGBA32: printf("B_RGBA32"); break; - + default: printf("%x", bmp.ColorSpace()); - break; + break; } printf(", %d, [", *(char*)bmp.Bits()); char *data = (char*)bmp.Bits(); @@ -416,7 +416,7 @@ reduce_color_depth(BBitmap &src32, BBitmap &dest8) return err; } #endif - + // IconHelper and IconForTypeHelper: // Adapter(?) classes needed to reuse icon tests among {Get,Set}Icon() and {Get,Set}IconForType() // What originally were meant to encapsulate the variations among calls to the various BMimeType @@ -443,12 +443,12 @@ public: BRect BitmapBounds(icon_size isize) { return isize == B_LARGE_ICON ? BRect(0,0,31,31) : BRect(0,0,15,15); } - + // Returns the proper bitmap bounds for this helper's icon size BRect BitmapBounds() { return BitmapBounds(size); - } - + } + // Used to call the appropriate GetIcon[ForType] function virtual status_t GetIcon(BMimeType &mime, BBitmap *icon) { return mime.GetIcon(icon, size); @@ -458,7 +458,7 @@ public: virtual status_t SetIcon(BMimeType &mime, BBitmap *icon) { return mime.SetIcon(icon, size); } - + // Used to call the appropriate DeleteIcon[ForType] function virtual status_t DeleteIcon(BMimeType &mime) { #if TEST_R5 @@ -467,28 +467,28 @@ public: return mime.DeleteIcon(size); #endif } - + BBitmap* TempBitmap() { return &bmpTemp; } - + BBitmap* Bitmap1() { return &bmp1; } - + BBitmap* Bitmap2() { return &bmp2; } - + icon_size Size() { return size; } - -protected: + +protected: BBitmap bmp1; BBitmap bmp2; BBitmap bmpTemp; - icon_size size; + icon_size size; }; class IconForTypeHelper : public IconHelper { @@ -525,18 +525,18 @@ public: SetAdapter(std::set &set) : fSet(set) { } virtual void Add(std::string value) { - fSet.insert(value); + fSet.insert(value); } protected: std::set &fSet; }; - + class QueueAdapter : public ContainerAdapter { public: QueueAdapter(std::queue &queue) : fQueue(queue) { } virtual void Add(std::string value) { - fQueue.push(value); + fQueue.push(value); } protected: std::queue &fQueue; @@ -553,7 +553,7 @@ MimeTypeTest::setUp() // local mime database which we'll use for certain OpenBeOS tests execCommand(string("mkdir ") + testDir + " ; copyattr -d -r -- " + mimeDatabaseDir + "/\* " + testDir - ); */ + ); */ // Setup our application fApplication = new BTestApp(testSig); if (fApplication->Init() != B_OK) { @@ -561,9 +561,9 @@ MimeTypeTest::setUp() delete fApplication; fApplication = NULL; } - + } - + // tearDown void MimeTypeTest::tearDown() @@ -608,11 +608,11 @@ dump_ref(entry_ref *ref, char* name = "ref") { } else printf("%s == ERROR", name); printf(" == (%ld, %Ld, '%s')\n", ref->device, ref->directory, ref->name); - + } else printf("%s == (NULL)\n", name); }*/ - + // App Hint void @@ -621,11 +621,11 @@ MimeTypeTest::AppHintTest() { BEntry entry(testApp); entry_ref appRef; CHK(entry.InitCheck() == B_OK); - CHK(entry.GetRef(&appRef) == B_OK); + CHK(entry.GetRef(&appRef) == B_OK); BEntry entry2(testApp2); entry_ref appRef2; CHK(entry2.InitCheck() == B_OK); - CHK(entry2.GetRef(&appRef2) == B_OK); + CHK(entry2.GetRef(&appRef2) == B_OK); // Uninitialized NextSubTest(); { @@ -660,9 +660,9 @@ MimeTypeTest::AppHintTest() { CHK(!mime.IsInstalled()); CHK(mime.SetAppHint(&appRef) == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetAppHint(&ref) == B_OK); + CHK(mime.GetAppHint(&ref) == B_OK); CHK(ref == appRef); - CHK(mime.SetAppHint(NULL) == B_OK); + CHK(mime.SetAppHint(NULL) == B_OK); CHK(mime.IsInstalled()); CHK(mime.GetAppHint(&ref) != B_OK); // B_ENTRY_NOT_FOUND #endif @@ -678,15 +678,15 @@ MimeTypeTest::AppHintTest() { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK(mime.DeleteAppHint() != B_OK); + CHK(mime.DeleteAppHint() != B_OK); CHK(!mime.IsInstalled()); CHK(mime.SetAppHint(&appRef) == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetAppHint(&ref) == B_OK); + CHK(mime.GetAppHint(&ref) == B_OK); CHK(ref == appRef); - CHK(mime.DeleteAppHint() == B_OK); + CHK(mime.DeleteAppHint() == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetAppHint(&ref) != B_OK); + CHK(mime.GetAppHint(&ref) != B_OK); #endif } // Non-installed type @@ -735,13 +735,13 @@ MimeTypeTest::AppHintTest() { { entry_ref ref(-1, -1, NULL); BMimeType mime(testType); - CHK(mime.InitCheck() == B_OK); + CHK(mime.InitCheck() == B_OK); // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) CHK(mime.Install() == B_OK); - CHK(mime.IsInstalled()); + CHK(mime.IsInstalled()); CHK(mime.SetAppHint(&appRef) == B_OK); CHK(mime.SetAppHint(&ref) != B_OK); // R5 == B_BAD_VALUE } @@ -750,16 +750,16 @@ MimeTypeTest::AppHintTest() { { entry_ref ref(0, 0, "__this_ought_not_exist__"); BMimeType mime(testType); - CHK(mime.InitCheck() == B_OK); + CHK(mime.InitCheck() == B_OK); // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); - CHK(mime.IsInstalled()); + CHK(mime.Install() == B_OK); + CHK(mime.IsInstalled()); CHK(mime.SetAppHint(&appRef) == B_OK); CHK(mime.SetAppHint(&ref) != B_OK); // R5 == B_ENTRY_NOT_FOUND - } + } // Installed Type, abstract entry_ref NextSubTest(); { @@ -770,19 +770,19 @@ MimeTypeTest::AppHintTest() { CHK(!entry.Exists()); CHK(entry.GetRef(&fakeRef) == B_OK); BMimeType mime(testType); - CHK(mime.InitCheck() == B_OK); + CHK(mime.InitCheck() == B_OK); // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); - CHK(mime.IsInstalled()); + CHK(mime.Install() == B_OK); + CHK(mime.IsInstalled()); CHK(mime.SetAppHint(&appRef) == B_OK); CHK(mime.SetAppHint(&fakeRef) == B_OK); CHK(mime.GetAppHint(&ref) == B_OK); CHK(ref == fakeRef); CHK(ref != appRef); - } + } } // Attr Info @@ -810,13 +810,13 @@ MimeTypeTest::AttrInfoTest() { CHK(msg2.AddInt32(attrInfoField_Type, B_DOUBLE_TYPE) == B_OK); CHK(msg2.AddBool(attrInfoField_Viewable, true) == B_OK); CHK(msg2.AddBool(attrInfoField_Editable, true) == B_OK); - + CHK(msg3.AddString(attrInfoField_Name, "Volume") == B_OK); CHK(msg3.AddString(attrInfoField_PublicName, "Loudness") == B_OK); CHK(msg3.AddInt32(attrInfoField_Type, B_DOUBLE_TYPE) == B_OK); CHK(msg3.AddBool(attrInfoField_Viewable, true) == B_OK); CHK(msg3.AddBool(attrInfoField_Editable, true) == B_OK); - + CHK(msgIncomplete1.AddString(attrInfoField_Name, "Color") == B_OK); CHK(msgIncomplete1.AddString(attrInfoField_PublicName, "The Color") == B_OK); CHK(msgIncomplete1.AddInt32(attrInfoField_Type, B_STRING_TYPE) == B_OK); @@ -828,7 +828,7 @@ MimeTypeTest::AttrInfoTest() { CHK(msgIncomplete1.AddInt32(attrInfoField_Type, B_INT32_TYPE) == B_OK); // CHK(msgIncomplete1.AddBool(attrInfoField_Viewable, false) == B_OK); CHK(msgIncomplete1.AddBool(attrInfoField_Editable, false) == B_OK); - + CHK(msgIncomplete2.AddString(attrInfoField_Name, "Color") == B_OK); // CHK(msgIncomplete2.AddString(attrInfoField_PublicName, "The Color") == B_OK); // CHK(msgIncomplete2.AddInt32(attrInfoField_Type, B_STRING_TYPE) == B_OK); @@ -847,12 +847,12 @@ MimeTypeTest::AttrInfoTest() { { BMimeType mime; BMessage msg; - + CHK(mime.InitCheck() == B_NO_INIT); CHK(mime.GetAttrInfo(&msg) != B_OK); // R5 == B_BAD_VALUE CHK(mime.SetAttrInfo(&msg) != B_OK); // R5 == B_BAD_VALUE } - + // NULL params NextSubTest(); { @@ -864,18 +864,18 @@ MimeTypeTest::AttrInfoTest() { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK(mime.DeleteAttrInfo() != B_OK); + CHK(mime.DeleteAttrInfo() != B_OK); CHK(!mime.IsInstalled()); msg1.RemoveName(typeField); // Clear "type" field, since SAI() just adds another CHK(mime.SetAttrInfo(&msg1) == B_OK); CHK(mime.IsInstalled()); CHK(msg != msg1); - CHK(mime.GetAttrInfo(&msg) == B_OK); + CHK(mime.GetAttrInfo(&msg) == B_OK); CHK(msg1.AddString(typeField, testType) == B_OK); // Add in "type" field as GAI() does CHK(msg == msg1); - CHK(mime.SetAttrInfo(NULL) == B_OK); + CHK(mime.SetAttrInfo(NULL) == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetAttrInfo(&msg) != B_OK); + CHK(mime.GetAttrInfo(&msg) != B_OK); #endif } // Delete test @@ -889,38 +889,38 @@ MimeTypeTest::AttrInfoTest() { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK(mime.DeleteAttrInfo() != B_OK); + CHK(mime.DeleteAttrInfo() != B_OK); CHK(!mime.IsInstalled()); msg1.RemoveName(typeField); // Clear "type" field, since SAI() just adds another CHK(mime.SetAttrInfo(&msg1) == B_OK); CHK(mime.IsInstalled()); CHK(msg != msg1); - CHK(mime.GetAttrInfo(&msg) == B_OK); + CHK(mime.GetAttrInfo(&msg) == B_OK); CHK(msg1.AddString(typeField, testType) == B_OK); // Add in "type" field as GAI() does CHK(msg == msg1); - CHK(mime.DeleteAttrInfo() == B_OK); + CHK(mime.DeleteAttrInfo() == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetAttrInfo(&msg) != B_OK); + CHK(mime.GetAttrInfo(&msg) != B_OK); #endif } - + // Improperly formatted BMessages NextSubTest(); { BMessage msg(WHAT); BMimeType mime(testType); CHK(mime.InitCheck() == B_OK); - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); // Initial Set()/Get() msgIncomplete1.RemoveName(typeField); // Clear "type" fields, since SAI() just adds another - msgIncomplete2.RemoveName(typeField); + msgIncomplete2.RemoveName(typeField); CHK(msg != msgIncomplete1); CHK(msg != msgIncomplete2); CHK(mime.SetAttrInfo(&msgIncomplete1) == B_OK); @@ -930,24 +930,24 @@ MimeTypeTest::AttrInfoTest() { CHK(msg == msgIncomplete1); CHK(msg != msgIncomplete2); } - + // Set() with improperly formatted message NextSubTest(); { BMessage msg(WHAT); BMimeType mime(testType); CHK(mime.InitCheck() == B_OK); - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); // Initial Set()/Get() msgIncomplete1.RemoveName(typeField); // Clear "type" fields, since SAI() just adds another - msgIncomplete2.RemoveName(typeField); + msgIncomplete2.RemoveName(typeField); CHK(msg != msgIncomplete1); CHK(msg != msgIncomplete2); CHK(mime.SetAttrInfo(&msgIncomplete1) == B_OK); @@ -957,7 +957,7 @@ MimeTypeTest::AttrInfoTest() { CHK(msg == msgIncomplete1); CHK(msg != msgIncomplete2); } - + // Set() with empty message NextSubTest(); { @@ -965,14 +965,14 @@ MimeTypeTest::AttrInfoTest() { BMessage msgEmpty(WHAT); BMessage msg(WHAT); CHK(msg.AddInt32("stuff", 1234) == B_OK); // Add an extra attribute to give us something to compare with - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); - + // Set(empty) CHK(msg != msgEmpty); CHK(mime.SetAttrInfo(&msgEmpty) == B_OK); @@ -980,7 +980,7 @@ MimeTypeTest::AttrInfoTest() { CHK(msgEmpty.AddString(typeField, testType) == B_OK); // Add in "type" fields as GFE() does CHK(msg == msgEmpty); } - + // Set() with extra attributes in message NextSubTest(); { @@ -992,17 +992,17 @@ MimeTypeTest::AttrInfoTest() { CHK(msgExtraSet.AddInt32("more_extras", 456) == B_OK); CHK(msgExtraSet.AddInt32("more_extras", 789) == B_OK); BMessage msgExtraGet(msgExtraSet); - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); - + // Set(extra)/Get(empty) msg1.RemoveName(typeField); // Clear "type" fields, since SFE() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msgExtraSet); CHK(mime.SetAttrInfo(&msgExtraSet) == B_OK); @@ -1011,13 +1011,13 @@ MimeTypeTest::AttrInfoTest() { CHK(msgExtraSet.AddString(typeField, testType) == B_OK); CHK(msg == msgExtraSet); CHK(msg != msg1); - + // Get(extra) NextSubTest(); CHK(mime.GetAttrInfo(&msgExtraGet) == B_OK); CHK(msgExtraGet == msgExtraSet); CHK(msgExtraGet != msg1); - + // Get(extra and then some) NextSubTest(); CHK(msgExtraGet.AddInt32("more_extras", 101112) == B_OK); @@ -1025,20 +1025,20 @@ MimeTypeTest::AttrInfoTest() { CHK(mime.GetAttrInfo(&msgExtraGet) == B_OK); // Reinitializes result (clearing extra fields) CHK(msgExtraGet == msgExtraSet); CHK(msgExtraGet != msg1); - - } + + } // Normal Function (Non-installed type) NextSubTest(); { BMimeType mime(testType); BMessage msg(WHAT); BMessage msg2(WHAT); - + CHK(mime.InitCheck() == B_OK); // Make sure the type isn't installed if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); - + CHK(!mime.IsInstalled()); CHK(mime.GetAttrInfo(&msg) != B_OK); // R5 == B_ENTRY_NOT_FOUND CHK(!mime.IsInstalled()); @@ -1048,24 +1048,24 @@ MimeTypeTest::AttrInfoTest() { CHK(msg.AddString(typeField, testType) == B_OK); // Add in "type" fields as GAI() does CHK(msg == msg2); } - + // Normal Function NextSubTest(); { BMessage msg(WHAT); BMimeType mime(testType); CHK(mime.InitCheck() == B_OK); - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); // Initial Set()/Get() msg1.RemoveName(typeField); // Clear "type" fields, since SAI() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msg2); CHK(mime.SetAttrInfo(&msg1) == B_OK); @@ -1079,7 +1079,7 @@ MimeTypeTest::AttrInfoTest() { NextSubTest(); CHK(msg.MakeEmpty() == B_OK); msg1.RemoveName(typeField); // Clear "type" fields, since SFE() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msg2); CHK(mime.SetAttrInfo(&msg2) == B_OK); @@ -1093,7 +1093,7 @@ MimeTypeTest::AttrInfoTest() { NextSubTest(); CHK(msg.MakeEmpty() == B_OK); msg1.RemoveName(typeField); // Clear "type" fields, since SFE() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msg2); #if !TEST_R5 @@ -1122,10 +1122,10 @@ MimeTypeTest::FileExtensionsTest() { CHK(msg2.AddString(fileExtField, ".data") == B_OK); CHK(msg2.AddString(fileExtField, ".txt") == B_OK); - + CHK(msg3.AddString(fileExtField, ".data") == B_OK); CHK(msg3.AddString(fileExtField, ".txt") == B_OK); - + CHK(msg1 == msg1); CHK(msg2 == msg2); CHK(msg3 == msg3); @@ -1138,7 +1138,7 @@ MimeTypeTest::FileExtensionsTest() { { BMessage msg(WHAT); BMimeType mime; - + CHK(mime.InitCheck() == B_NO_INIT); CHK(mime.GetFileExtensions(&msg) != B_OK); // R5 == B_BAD_VALUE CHK(mime.SetFileExtensions(&msg) != B_OK); // R5 == B_BAD_VALUE @@ -1154,18 +1154,18 @@ MimeTypeTest::FileExtensionsTest() { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK(mime.DeleteFileExtensions() != B_OK); + CHK(mime.DeleteFileExtensions() != B_OK); CHK(!mime.IsInstalled()); msg1.RemoveName(typeField); // Clear "type" field, since SAI() just adds another CHK(mime.SetFileExtensions(&msg1) == B_OK); CHK(mime.IsInstalled()); CHK(msg != msg1); - CHK(mime.GetFileExtensions(&msg) == B_OK); + CHK(mime.GetFileExtensions(&msg) == B_OK); CHK(msg1.AddString(typeField, testType) == B_OK); // Add in "type" field as GAI() does CHK(msg == msg1); - CHK(mime.SetFileExtensions(NULL) == B_OK); + CHK(mime.SetFileExtensions(NULL) == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetFileExtensions(&msg) != B_OK); + CHK(mime.GetFileExtensions(&msg) != B_OK); #endif } // Delete test @@ -1179,18 +1179,18 @@ MimeTypeTest::FileExtensionsTest() { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK(mime.DeleteFileExtensions() != B_OK); + CHK(mime.DeleteFileExtensions() != B_OK); CHK(!mime.IsInstalled()); msg1.RemoveName(typeField); // Clear "type" field, since SAI() just adds another CHK(mime.SetFileExtensions(&msg1) == B_OK); CHK(mime.IsInstalled()); CHK(msg != msg1); - CHK(mime.GetFileExtensions(&msg) == B_OK); + CHK(mime.GetFileExtensions(&msg) == B_OK); CHK(msg1.AddString(typeField, testType) == B_OK); // Add in "type" field as GAI() does CHK(msg == msg1); - CHK(mime.DeleteFileExtensions() == B_OK); + CHK(mime.DeleteFileExtensions() == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetFileExtensions(&msg) != B_OK); + CHK(mime.GetFileExtensions(&msg) != B_OK); #endif } // Set() with empty message @@ -1200,14 +1200,14 @@ MimeTypeTest::FileExtensionsTest() { BMessage msgEmpty(WHAT); BMessage msg(WHAT); CHK(msg.AddInt32("stuff", 1234) == B_OK); // Add an extra attribute to give us something to compare with - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); - + // Set(empty) CHK(msg != msgEmpty); CHK(mime.SetFileExtensions(&msgEmpty) == B_OK); @@ -1226,17 +1226,17 @@ MimeTypeTest::FileExtensionsTest() { CHK(msgExtraSet.AddInt32("more_extras", 456) == B_OK); CHK(msgExtraSet.AddInt32("more_extras", 789) == B_OK); BMessage msgExtraGet(msgExtraSet); - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); - + // Set(extra)/Get(empty) msg1.RemoveName(typeField); // Clear "type" fields, since SFE() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msgExtraSet); CHK(mime.SetFileExtensions(&msgExtraSet) == B_OK); @@ -1245,13 +1245,13 @@ MimeTypeTest::FileExtensionsTest() { CHK(msgExtraSet.AddString(typeField, testType) == B_OK); CHK(msg == msgExtraSet); CHK(msg != msg1); - + // Get(extra) NextSubTest(); CHK(mime.GetFileExtensions(&msgExtraGet) == B_OK); CHK(msgExtraGet == msgExtraSet); CHK(msgExtraGet != msg1); - + // Get(extra and then some) NextSubTest(); CHK(msgExtraGet.AddInt32("more_extras", 101112) == B_OK); @@ -1259,24 +1259,24 @@ MimeTypeTest::FileExtensionsTest() { CHK(mime.GetFileExtensions(&msgExtraGet) == B_OK); // Reinitializes result (clearing extra fields) CHK(msgExtraGet == msgExtraSet); CHK(msgExtraGet != msg1); - + } // Normal function NextSubTest(); { BMessage msg(WHAT); BMimeType mime(testType); - + // Uninstall then reinstall to clear attributes if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); // Initial Set()/Get() msg1.RemoveName(typeField); // Clear "type" fields, since SFE() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msg2); CHK(mime.SetFileExtensions(&msg1) == B_OK); @@ -1290,7 +1290,7 @@ MimeTypeTest::FileExtensionsTest() { NextSubTest(); CHK(msg.MakeEmpty() == B_OK); msg1.RemoveName(typeField); // Clear "type" fields, since SFE() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msg2); CHK(mime.SetFileExtensions(&msg2) == B_OK); @@ -1304,7 +1304,7 @@ MimeTypeTest::FileExtensionsTest() { NextSubTest(); CHK(msg.MakeEmpty() == B_OK); msg1.RemoveName(typeField); // Clear "type" fields, since SFE() just adds another - msg2.RemoveName(typeField); + msg2.RemoveName(typeField); CHK(msg != msg1); CHK(msg != msg2); #if !TEST_R5 @@ -1324,7 +1324,7 @@ MimeTypeTest::FileExtensionsTest() { void MimeTypeTest::IconTest(IconHelper &helper) { BBitmap *bmp = helper.TempBitmap(); - // Unitialized + // Unitialized NextSubTest(); { BMimeType mime; @@ -1388,17 +1388,17 @@ MimeTypeTest::IconTest(IconHelper &helper) { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK(helper.DeleteIcon(mime) != B_OK); + CHK(helper.DeleteIcon(mime) != B_OK); CHK(!mime.IsInstalled()); CHK(helper.SetIcon(mime, helper.Bitmap2()) == B_OK); CHK(mime.IsInstalled()); fill_bitmap(*bmp, 100); CHK(*bmp != *helper.Bitmap2()); - CHK(helper.GetIcon(mime, bmp) == B_OK); + CHK(helper.GetIcon(mime, bmp) == B_OK); CHK(*bmp == *helper.Bitmap2()); - CHK(helper.DeleteIcon(mime) == B_OK); + CHK(helper.DeleteIcon(mime) == B_OK); CHK(mime.IsInstalled()); - CHK(helper.GetIcon(mime, bmp) != B_OK); + CHK(helper.GetIcon(mime, bmp) != B_OK); #endif } // Invalid Bitmap Size (small -- 10x10) @@ -1423,7 +1423,7 @@ MimeTypeTest::IconTest(IconHelper &helper) { CHK(helper.SetIcon(mime, &testBmp) != B_OK); // R5 == B_BAD_VALUE CHK(helper.GetIcon(mime, bmp) == B_OK); CHK(*bmp == *helper.Bitmap1()); - CHK(*bmp != testBmp); + CHK(*bmp != testBmp); // Test Get() fill_bitmap(testBmp, 3); CHK(helper.SetIcon(mime, helper.Bitmap1()) == B_OK); @@ -1456,7 +1456,7 @@ MimeTypeTest::IconTest(IconHelper &helper) { fill_bitmap(testBmp, 3); CHK(helper.SetIcon(mime, helper.Bitmap1()) == B_OK); CHK(helper.GetIcon(mime, &testBmp) != B_OK); // R5 == B_BAD_VALUE - } + } // Non-B_CMAP8 Color Depth (not really supported under R5) NextSubTest(); { @@ -1490,7 +1490,7 @@ MimeTypeTest::IconTest(IconHelper &helper) { CHK(*bmp != testBmp); // Shouldn't match, since SetIcon() reduces to B_CMAP8 CHK(*bmp == testBmp8); // *Should* match, since it's the result of a similar reduction #endif - } + } // Normal Function NextSubTest(); { @@ -1513,19 +1513,19 @@ MimeTypeTest::IconTest(IconHelper &helper) { CHK(helper.SetIcon(mime, helper.Bitmap2()) == B_OK); CHK(helper.GetIcon(mime, bmp) == B_OK); CHK(*bmp == *helper.Bitmap2()); - CHK(*bmp != *helper.Bitmap1()); - } + CHK(*bmp != *helper.Bitmap1()); + } } // Icon For Type Helper Functions void MimeTypeTest::IconForTypeTest(IconForTypeHelper &helper) { - IconTest(helper); // First run all the icon tests + IconTest(helper); // First run all the icon tests // Then do some IconForType() specific tests - + BBitmap *bmp = helper.TempBitmap(); - + // Invalid MIME string NextSubTest(); { @@ -1570,7 +1570,7 @@ MimeTypeTest::IconForTypeTest(IconForTypeHelper &helper) { CHK(mime.SetIconForType(NULL, NULL, helper.Size()) == B_OK); CHK(mime.GetIconForType(NULL, bmp, helper.Size()) != B_OK); // B_ENTRY_NOT_FOUND CHK(mime.GetIcon(bmp, helper.Size()) != B_OK); // B_ENTRY_NOT_FOUND - } + } } void @@ -1603,7 +1603,7 @@ bool isMIMESupertype(const char *type) { err = !type || !BMimeType::IsValid(type); // See if the type is the same as it's supertype - if (!err) + if (!err) err = sub.SetTo(type); if (!err) return sub.GetSupertype(&super) == B_BAD_VALUE; @@ -1621,7 +1621,7 @@ MimeTypeTest::VerifyInstalledTypes() { // Get the list of installed types CHK(BMimeType::GetInstalledTypes(&msg) == B_OK); - + // Add all the type strings to a std::set std::set typeSet; SetAdapter typeAdapter(typeSet); @@ -1632,7 +1632,7 @@ MimeTypeTest::VerifyInstalledTypes() { // any files with names made of invalid characters, in case some bozo // manually added such a file :-) BDirectory rootDir(mimeDatabaseDir.c_str()); - BEntry superEntry; + BEntry superEntry; CHK(rootDir.InitCheck() == B_OK); rootDir.Rewind(); while (true) { @@ -1642,20 +1642,20 @@ MimeTypeTest::VerifyInstalledTypes() { CHK(!err); // Any other error is unacceptable :-) - // Get the leaf name + // Get the leaf name char superLeafMixed[B_PATH_NAME_LENGTH+1]; CHK(superEntry.GetName(superLeafMixed) == B_OK); std::string superLeaf; to_lower(superLeafMixed, superLeaf); - + // We're only interested in directories, as they map to // supertypes (and since they map thusly, they must also // be valid MIME strings) if (superEntry.IsDirectory() && BMimeType::IsValid(superLeaf.c_str())) { - // First, find and remove the supertype from our set + // First, find and remove the supertype from our set CHK(typeSet.find(superLeaf.c_str()) != typeSet.end()); typeSet.erase(superLeaf.c_str()); - + // Second, iterate through all the entries in the directory. // If the entry designates a valid MIME string, find it // in the set and remove it. @@ -1667,15 +1667,15 @@ MimeTypeTest::VerifyInstalledTypes() { status_t err = superDir.GetNextEntry(&subEntry); if (err == B_ENTRY_NOT_FOUND) break; // End of directory listing - + CHK(!err); // Any other error is unacceptable :-) - + // Get the leaf name char subLeafMixed[B_PATH_NAME_LENGTH+1]; CHK(subEntry.GetName(subLeafMixed) == B_OK); std::string subLeaf; to_lower(subLeafMixed, subLeaf); - + // Verify it's a valid mime string. If so, find and remove from our set std::string subType = superLeaf + "/" + subLeaf; if (BMimeType::IsValid(subType.c_str())) { @@ -1684,10 +1684,10 @@ MimeTypeTest::VerifyInstalledTypes() { CHK(typeSet.find(subType.c_str()) != typeSet.end()); typeSet.erase(subType.c_str()); } - } + } } } - + // At this point our set should be empty :-) If it's not, you might check // that you haven't added any superfluous files to your MIME database (like // a __mime_table backup, for instance). @@ -1701,18 +1701,18 @@ MimeTypeTest::VerifyInstalledTypes() { // Get the list of installed types CHK(BMimeType::GetInstalledSupertypes(&msg) == B_OK); // msg.PrintToStream(); - + // Add all the type strings to a std::set std::set typeSet; SetAdapter typeAdapter(typeSet); FillWithMimeTypes(typeAdapter, msg, "super_types"); - + // Manually verify that the set of types returned by GetInstalledSupertypes() // and the types present in the database are exactly the same (ignoring // any files with names made of invalid characters, in case some bozo // manually added such a file :-) BDirectory rootDir(mimeDatabaseDir.c_str()); - BEntry superEntry; + BEntry superEntry; CHK(rootDir.InitCheck() == B_OK); rootDir.Rewind(); while (true) { @@ -1722,12 +1722,12 @@ MimeTypeTest::VerifyInstalledTypes() { CHK(!err); // Any other error is unacceptable :-) - // Get the leaf name + // Get the leaf name char superLeafMixed[B_PATH_NAME_LENGTH+1]; CHK(superEntry.GetName(superLeafMixed) == B_OK); std::string superLeaf; to_lower(superLeafMixed, superLeaf); - + // We're only interested in directories, as they map to // supertypes (and since they map thusly, they must also // be valid MIME strings) @@ -1735,17 +1735,17 @@ MimeTypeTest::VerifyInstalledTypes() { // First, find and remove the supertype from our set CHK(typeSet.find(superLeaf.c_str()) != typeSet.end()); typeSet.erase(superLeaf.c_str()); - + // Second, get the list of corresponding subtypes and add them // to a std::set to be used for verification BMessage msg; CHK(BMimeType::GetInstalledTypes(superLeaf.c_str(), &msg) == B_OK); // msg.PrintToStream(); - + std::set subtypeSet; SetAdapter subtypeAdapter(subtypeSet); FillWithMimeTypes(subtypeAdapter, msg, "types"); - + // Third, iterate through all the entries in the directory. // If the entry designates a valid MIME string, find it // in the subtype set and remove it. @@ -1757,15 +1757,15 @@ MimeTypeTest::VerifyInstalledTypes() { status_t err = superDir.GetNextEntry(&subEntry); if (err == B_ENTRY_NOT_FOUND) break; // End of directory listing - + CHK(!err); // Any other error is unacceptable :-) - + // Get the leaf name char subLeafMixed[B_PATH_NAME_LENGTH+1]; CHK(subEntry.GetName(subLeafMixed) == B_OK); std::string subLeaf; to_lower(subLeafMixed, subLeaf); - + // Verify it's a valid mime string. If so, find and remove from our set std::string subType = superLeaf + "/" + subLeaf; if (BMimeType::IsValid(subType.c_str())) { @@ -1773,17 +1773,17 @@ MimeTypeTest::VerifyInstalledTypes() { subtypeSet.erase(subType.c_str()); } } - + // At this point our subtype set should be empty :-) - CHK(subtypeSet.size() == 0); - + CHK(subtypeSet.size() == 0); + } } - + // At this point our set should be empty :-) - CHK(typeSet.size() == 0); + CHK(typeSet.size() == 0); } - + } void @@ -1854,9 +1854,9 @@ MimeTypeTest::ShortDescriptionTest() { DescriptionTest(&BMimeType::GetShortDescription, &BMimeType::SetShortDescription, #if TEST_R5 NULL -#else +#else &BMimeType::DeleteShortDescription -#endif +#endif ); } @@ -1867,9 +1867,9 @@ MimeTypeTest::LongDescriptionTest() { DescriptionTest(&BMimeType::GetLongDescription, &BMimeType::SetLongDescription, #if TEST_R5 NULL -#else +#else &BMimeType::DeleteLongDescription -#endif +#endif ); } @@ -1888,7 +1888,7 @@ MimeTypeTest::DescriptionTest(GetDescriptionFunc getDescr, SetDescriptionFunc se CPPUNIT_ASSERT(mime.InitCheck() == B_NO_INIT); CPPUNIT_ASSERT((mime.*getDescr)(str) != B_OK); // R5 == B_BAD_VALUE CPPUNIT_ASSERT((mime.*setDescr)(str) != B_OK); // R5 == B_BAD_VALUE - } + } // Non-installed type NextSubTest(); { @@ -1918,7 +1918,7 @@ MimeTypeTest::DescriptionTest(GetDescriptionFunc getDescr, SetDescriptionFunc se if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK((mime.*getDescr)(NULL) == B_BAD_VALUE); + CHK((mime.*getDescr)(NULL) == B_BAD_VALUE); CHK(!mime.IsInstalled()); CHK((mime.*setDescr)(NULL) == B_ENTRY_NOT_FOUND); // Trying to delete non-existent attribute CHK(!mime.IsInstalled()); @@ -1943,16 +1943,16 @@ MimeTypeTest::DescriptionTest(GetDescriptionFunc getDescr, SetDescriptionFunc se if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK((mime.*deleteDescr)() != B_OK); + CHK((mime.*deleteDescr)() != B_OK); CHK(!mime.IsInstalled()); CHK((mime.*setDescr)(testDescr) == B_OK); CHK(mime.IsInstalled()); str[0] = 0; - CHK((mime.*getDescr)(str) == B_OK); + CHK((mime.*getDescr)(str) == B_OK); CHK(strcmp(str, testDescr) == 0); - CHK((mime.*deleteDescr)() == B_OK); + CHK((mime.*deleteDescr)() == B_OK); CHK(mime.IsInstalled()); - CHK((mime.*getDescr)(str) != B_OK); + CHK((mime.*getDescr)(str) != B_OK); #endif } // Installed type @@ -1976,7 +1976,7 @@ MimeTypeTest::DescriptionTest(GetDescriptionFunc getDescr, SetDescriptionFunc se // Followup Set()/Get() CHK((mime.*setDescr)(testDescr2) == B_OK); CHK((mime.*getDescr)(str) == B_OK); - CHK(strcmp(str, testDescr2) == 0); + CHK(strcmp(str, testDescr2) == 0); } // Installed Type, Description Too Long NextSubTest(); @@ -1997,7 +1997,7 @@ MimeTypeTest::DescriptionTest(GetDescriptionFunc getDescr, SetDescriptionFunc se CHK((mime.*setDescr)(testDescr) == B_OK); CHK((mime.*setDescr)(longDescr) != B_OK); // R5 == B_BAD_VALUE CHK((mime.*getDescr)(str) == B_OK); - CHK(strcmp(str, testDescr) == 0); + CHK(strcmp(str, testDescr) == 0); } } @@ -2017,7 +2017,7 @@ MimeTypeTest::PreferredAppTest() { CPPUNIT_ASSERT(mime.InitCheck() == B_NO_INIT); CPPUNIT_ASSERT(mime.GetPreferredApp(str) != B_OK); // R5 == B_BAD_VALUE CPPUNIT_ASSERT(mime.SetPreferredApp(str) != B_OK); // R5 == B_BAD_VALUE - } + } // Non-installed type NextSubTest(); { @@ -2055,12 +2055,12 @@ MimeTypeTest::PreferredAppTest() { CHK(!mime.IsInstalled()); CHK(mime.SetPreferredApp(NULL) != B_OK); // OBOS == B_ENTRY_NOT_FOUND CHK(!mime.IsInstalled()); - CHK(mime.SetPreferredApp(testSig) == B_OK); + CHK(mime.SetPreferredApp(testSig) == B_OK); CHK(mime.IsInstalled()); str[0] = 0; CHK(mime.GetPreferredApp(str) == B_OK); CHK(strcmp(str, testSig) == 0); - CHK(mime.SetPreferredApp(NULL) == B_OK); + CHK(mime.SetPreferredApp(NULL) == B_OK); CHK(mime.IsInstalled()); str[0] = 0; CHK(mime.GetPreferredApp(str) != B_OK); // OBOS == B_ENTRY_NOT_FOUND @@ -2092,16 +2092,16 @@ MimeTypeTest::PreferredAppTest() { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); CHK(!mime.IsInstalled()); - CHK(mime.DeletePreferredApp() != B_OK); + CHK(mime.DeletePreferredApp() != B_OK); CHK(!mime.IsInstalled()); CHK(mime.SetPreferredApp(testSig) == B_OK); CHK(mime.IsInstalled()); str[0] = 0; - CHK(mime.GetPreferredApp(str) == B_OK); + CHK(mime.GetPreferredApp(str) == B_OK); CHK(strcmp(str, testSig) == 0); - CHK(mime.DeletePreferredApp() == B_OK); + CHK(mime.DeletePreferredApp() == B_OK); CHK(mime.IsInstalled()); - CHK(mime.GetPreferredApp(str) != B_OK); + CHK(mime.GetPreferredApp(str) != B_OK); #endif } // Installed type @@ -2124,7 +2124,7 @@ MimeTypeTest::PreferredAppTest() { // Followup Set()/Get() CHK(mime.SetPreferredApp(testSig2) == B_OK); CHK(mime.GetPreferredApp(str) == B_OK); - CHK(strcmp(str, testSig2) == 0); + CHK(strcmp(str, testSig2) == 0); } // Installed Type, Signature Too Long NextSubTest(); @@ -2144,7 +2144,7 @@ MimeTypeTest::PreferredAppTest() { CHK(mime.SetPreferredApp(testSig) == B_OK); CHK(mime.SetPreferredApp(longSig) != B_OK); // R5 == B_BAD_VALUE CHK(mime.GetPreferredApp(str) == B_OK); - CHK(strcmp(str, testSig) == 0); + CHK(strcmp(str, testSig) == 0); } } @@ -2172,17 +2172,17 @@ to_lower(const char *str) { void remove_type(const char *type, const char *databaseDir) { CHK(type != NULL); - + // Since the MIME types are converted to lower case before their // corresponding file is created in the database, we need to do // the same std::string typeLower; - to_lower(type, typeLower); + to_lower(type, typeLower); BEntry entry((std::string(mimeDatabaseDir) + "/" + typeLower).c_str()); - CHK(entry.InitCheck() == B_OK); - if (entry.Exists()) - CHK(entry.Remove() == B_OK); + CHK(entry.InitCheck() == B_OK); + if (entry.Exists()) + CHK(entry.Remove() == B_OK); CHK(!entry.Exists()); } @@ -2196,10 +2196,10 @@ type_exists(const char *type, const char *databaseDir) { // corresponding file is created in the database, we need to do // the same std::string typeLower; - to_lower(type, typeLower); + to_lower(type, typeLower); BEntry entry((std::string(databaseDir) + "/" + typeLower).c_str()); - CHK(entry.InitCheck() == B_OK); + CHK(entry.InitCheck() == B_OK); return entry.Exists(); } @@ -2242,23 +2242,23 @@ MimeTypeTest::InstallDeleteTest() { CHK(!type_exists(testType)); CHK(!mime.IsInstalled()); } - + } void FillWithMimeTypes(ContainerAdapter &container, BMessage &typeMessage, const char* fieldName) { type_code type; int32 count; status_t err; - -// typeMessage.PrintToStream(); - + +// typeMessage.PrintToStream(); + // Get a count of types in the message err = typeMessage.GetInfo(fieldName, &type, &count); if (err == B_NAME_NOT_FOUND) count = 0; // No such types installed in the database! :-) else CHK(err == B_OK); // Any other error is unacceptable - + // Add them all to the container, after converting to lowercase and // checking validity for (int i = 0; i < count; i++) { @@ -2293,7 +2293,7 @@ types_fields_are_identical(const BMessage &msg1, const BMessage &msg2) result &= to_lower(str1) == to_lower(str2); i++; } - return result; + return result; } bool @@ -2304,7 +2304,7 @@ is_supporting_app_for_all_types_in_message(const char *app, const BMessage &msg) for (int i = 0; msg.FindString(typesField, i, &str) == B_OK; i++) { BMimeType supportedType(str); BMessage appMsg; - + // Get a list of supporting apps CHK(supportedType.InitCheck() == B_OK); CHK(supportedType.GetSupportingApps(&appMsg) == B_OK); @@ -2312,7 +2312,7 @@ is_supporting_app_for_all_types_in_message(const char *app, const BMessage &msg) // cout << str << endl; // cout << "-----------------------------------------------------------" << endl; // appMsg.PrintToStream(); - + // Look for our supporting app int32 directlySupportingAppsCount; CHK(appMsg.FindInt32("be:sub", &directlySupportingAppsCount) == B_OK); @@ -2356,21 +2356,21 @@ MimeTypeTest::SupportedTypesTest() { CHK(msg3 == msg3); CHK(msg1a != msg2); CHK(msg1a != msg3); - CHK(msg1a != msgEmpty); + CHK(msg1a != msgEmpty); // Uninitialized NextSubTest(); { BMimeType mime; BMessage msg; - + CHK(mime.InitCheck() == B_NO_INIT); CHK(mime.SetSupportedTypes(&msg, true) != B_OK); CHK(mime.SetSupportedTypes(&msg, false) != B_OK); CHK(mime.GetSupportedTypes(&msg) != B_OK); - CHK(mime.DeleteSupportedTypes() != B_OK); + CHK(mime.DeleteSupportedTypes() != B_OK); } - + // Test that deleting a type from the database also removes // the app as a supporting app for all types it previously // supported @@ -2388,15 +2388,15 @@ MimeTypeTest::SupportedTypesTest() { // Verify that each of those types now lists the // type as a directly supporting app CHK(is_supporting_app_for_all_types_in_message(testType, msg3) == true); - + // Delete the type CHK(mime.Delete() == B_OK); - + // Verify that each of those types no longer lists the // type as a directly supporting app - CHK(is_supporting_app_for_all_types_in_message(testType, msg3) == false); + CHK(is_supporting_app_for_all_types_in_message(testType, msg3) == false); } - + // Test that SetSupportedTypes(..., false) does not remove the app as a supporting // app for newly unsupported types, while SetSupportedTypes(..., true) does. Also // test that supported types stranded by multiple sequential calls to @@ -2412,35 +2412,35 @@ MimeTypeTest::SupportedTypesTest() { if (mime.IsInstalled()) CHK(mime.Delete() == B_OK); if (!mime.IsInstalled()) - CHK(mime.Install() == B_OK); + CHK(mime.Install() == B_OK); CHK(mime.IsInstalled()); // Set a list of supported types CHK(mime.SetSupportedTypes(&msg3, true) == B_OK); CHK(mime.GetSupportedTypes(&msg) == B_OK); - CHK(types_fields_are_identical(msg3, msg) == true); - CHK(types_fields_are_identical(msg2, msg) == false); - CHK(types_fields_are_identical(msg1a, msg) == false); - CHK(types_fields_are_identical(msg1b, msg) == false); - CHK(types_fields_are_identical(msgEmpty, msg) == false); - + CHK(types_fields_are_identical(msg3, msg) == true); + CHK(types_fields_are_identical(msg2, msg) == false); + CHK(types_fields_are_identical(msg1a, msg) == false); + CHK(types_fields_are_identical(msg1b, msg) == false); + CHK(types_fields_are_identical(msgEmpty, msg) == false); + // Verify that each of those types now lists the // type as a directly supporting app CHK(is_supporting_app_for_all_types_in_message(testType, msg3) == true); CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == true); CHK(is_supporting_app_for_all_types_in_message(testType, msg1a) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1b) == true); - + // Set (no sync) to a new list of supported types containing one // fewer type than the original list CHK(mime.SetSupportedTypes(&msg2, false) == B_OK); CHK(mime.GetSupportedTypes(&msg) == B_OK); - CHK(types_fields_are_identical(msg3, msg) == false); - CHK(types_fields_are_identical(msg2, msg) == true); - CHK(types_fields_are_identical(msg1a, msg) == false); - CHK(types_fields_are_identical(msg1b, msg) == false); - CHK(types_fields_are_identical(msgEmpty, msg) == false); - + CHK(types_fields_are_identical(msg3, msg) == false); + CHK(types_fields_are_identical(msg2, msg) == true); + CHK(types_fields_are_identical(msg1a, msg) == false); + CHK(types_fields_are_identical(msg1b, msg) == false); + CHK(types_fields_are_identical(msgEmpty, msg) == false); + // Verify that the app is still listed as a supporting app for // *all* of the originally supported types (even the one no longer // listed as being supported) @@ -2448,17 +2448,17 @@ MimeTypeTest::SupportedTypesTest() { CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == true); CHK(is_supporting_app_for_all_types_in_message(testType, msg1a) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1b) == true); - + // Set (no sync) to a new list of supported types containing an // entirely new, never supported type CHK(mime.SetSupportedTypes(&msg1a, false) == B_OK); CHK(mime.GetSupportedTypes(&msg) == B_OK); - CHK(types_fields_are_identical(msg3, msg) == false); - CHK(types_fields_are_identical(msg2, msg) == false); - CHK(types_fields_are_identical(msg1a, msg) == true); - CHK(types_fields_are_identical(msg1b, msg) == false); - CHK(types_fields_are_identical(msgEmpty, msg) == false); - + CHK(types_fields_are_identical(msg3, msg) == false); + CHK(types_fields_are_identical(msg2, msg) == false); + CHK(types_fields_are_identical(msg1a, msg) == true); + CHK(types_fields_are_identical(msg1b, msg) == false); + CHK(types_fields_are_identical(msgEmpty, msg) == false); + // Verify that the app is still listed as a supporting app for // *all* of the originally supported types (none of which are // supported any longer) as well as the newly supported type. @@ -2472,12 +2472,12 @@ MimeTypeTest::SupportedTypesTest() { // removed. CHK(mime.SetSupportedTypes(&msg1b, false) == B_OK); CHK(mime.GetSupportedTypes(&msg) == B_OK); - CHK(types_fields_are_identical(msg3, msg) == false); - CHK(types_fields_are_identical(msg2, msg) == false); - CHK(types_fields_are_identical(msg1a, msg) == false); - CHK(types_fields_are_identical(msg1b, msg) == true); - CHK(types_fields_are_identical(msgEmpty, msg) == false); - + CHK(types_fields_are_identical(msg3, msg) == false); + CHK(types_fields_are_identical(msg2, msg) == false); + CHK(types_fields_are_identical(msg1a, msg) == false); + CHK(types_fields_are_identical(msg1b, msg) == true); + CHK(types_fields_are_identical(msgEmpty, msg) == false); + // Verify that the app is still listed as a supporting app for // *all* of the originally supported types (only one of which is // supported any longer) as well as the previous supported type. @@ -2490,24 +2490,24 @@ MimeTypeTest::SupportedTypesTest() { // one type from the original list of supported types) CHK(mime.SetSupportedTypes(&msg1b, true) == B_OK); CHK(mime.GetSupportedTypes(&msg) == B_OK); - CHK(types_fields_are_identical(msg3, msg) == false); - CHK(types_fields_are_identical(msg2, msg) == false); - CHK(types_fields_are_identical(msg1a, msg) == false); - CHK(types_fields_are_identical(msg1b, msg) == true); - CHK(types_fields_are_identical(msgEmpty, msg) == false); + CHK(types_fields_are_identical(msg3, msg) == false); + CHK(types_fields_are_identical(msg2, msg) == false); + CHK(types_fields_are_identical(msg1a, msg) == false); + CHK(types_fields_are_identical(msg1b, msg) == true); + CHK(types_fields_are_identical(msgEmpty, msg) == false); // Verify that the app is now only listed as a supporting app for the // most recently supported type. CHK(is_supporting_app_for_all_types_in_message(testType, msg3) == false); - CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == false); + CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1a) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1b) == true); - + // Test SetSupportedTypes(NULL, false) for shits and giggles CHK(mime.SetSupportedTypes(NULL, false) == B_OK); CHK(mime.GetSupportedTypes(&msg) == B_ENTRY_NOT_FOUND); CHK(is_supporting_app_for_all_types_in_message(testType, msg3) == false); - CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == false); + CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1a) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1b) == true); @@ -2515,12 +2515,12 @@ MimeTypeTest::SupportedTypesTest() { // apps mappings, even if the supported types attribute has already // been removed. CHK(mime.SetSupportedTypes(NULL, true) == B_ENTRY_NOT_FOUND); - CHK(mime.GetSupportedTypes(&msg) == B_ENTRY_NOT_FOUND); + CHK(mime.GetSupportedTypes(&msg) == B_ENTRY_NOT_FOUND); CHK(is_supporting_app_for_all_types_in_message(testType, msg3) == false); - CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == false); + CHK(is_supporting_app_for_all_types_in_message(testType, msg2) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1a) == false); CHK(is_supporting_app_for_all_types_in_message(testType, msg1b) == false); - } + } #endif // #if TEST_R5 else } @@ -2553,13 +2553,13 @@ MimeTypeTest::SupportingAppsTest() { msg.PrintToStream(); } */ NextSubTest(); - if (true) + if (true) { std::set typeList; // Stores all installed MIME types std::set appList; // Stores all installed application subtypes std::map< std::string, std::set > typeAppMap; // Stores mapping of types to apps that support them std::map< std::string, std::set > fakeTypeAppMap; // Used to keep timing info for R5 and OBOS tests orthogonal - + // Get a list of all the types in the database { BMessage msg; @@ -2575,7 +2575,7 @@ MimeTypeTest::SupportingAppsTest() { SetAdapter appAdapter(appList); FillWithMimeTypes(appAdapter, msg, "types"); } - + // For each app in the database, manually get a list of the MIME types // it supports by reading its META:FILE_TYPES attribute from the database, // and add the app to the type->app map for each such type @@ -2584,31 +2584,31 @@ MimeTypeTest::SupportingAppsTest() { for (i = appList.begin(); i != appList.end(); i++) { // Grab the next application std::string app = *i; - + // The leaf is all we're interested in -- it's the subtype // CHK(StorageKit::split_path(app.c_str(), dir, leaf) == B_OK); std::string appFile = std::string(mimeDatabaseDir) + "/" + app; // printf("'%s'\n", appFile.c_str()); BNode node(appFile.c_str()); CHK(node.InitCheck() == B_OK); - + // Find out how much data there is in the META:FILE_TYPES attribute // (assuming it even exists, which it may not...) attr_info info; if (node.GetAttrInfo("META:FILE_TYPES", &info) == B_OK) { // printf("attr_info: type == %lx, size == %lld\n", info.type, info.size); // Attribute exists, so alloc a buffer and read it - char *buffer = new char[info.size+1]; + char *buffer = new char[info.size+1]; CHK(node.ReadAttr("META:FILE_TYPES", B_MESSAGE_TYPE, 0, buffer, info.size) == info.size); BMessage msg; if (msg.Unflatten(buffer) == B_OK) { // msg.PrintToStream(); - + // Fill up a list with all the supported types std::set supportList; SetAdapter supportAdapter(supportList); FillWithMimeTypes(supportAdapter, msg, "types"); - + // For each type, add the current application as a supporting // app in our type->apps map for (std::set::iterator type = supportList.begin(); @@ -2626,14 +2626,14 @@ MimeTypeTest::SupportingAppsTest() { printf("Warning: Unable to unflatten META:FILE_TYPES attribute for '%s' type.\n", app.c_str()); } - + delete buffer; - + } } } -//#if !TEST_R5 +//#if !TEST_R5 // Now, add in all the types listed in MIME_DB_DIR/__mime_table { BEntry entry((std::string(mimeDatabaseDir) + "/__mime_table").c_str()); @@ -2645,9 +2645,9 @@ MimeTypeTest::SupportingAppsTest() { CHK(msg.Unflatten(&file) == B_OK); // msg.PrintToStream(); - - char *type; - uint32 typeVal; + + char *type; + uint32 typeVal; int32 count; for (int i = 0; msg.GetInfo(B_STRING_TYPE, i, &type, &typeVal, &count) == B_OK; i++ ) { // Add all the associated applications. Interestingly (or maybe not), @@ -2657,17 +2657,17 @@ MimeTypeTest::SupportingAppsTest() { const char *app; for (int j = 0; j < count; j++) { CHK(msg.FindString(type, j, &app) == B_OK); -#if TEST_R5 +#if TEST_R5 typeAppMap[type].insert(to_lower(app)); #else fakeTypeAppMap[type].insert(to_lower(app)); #endif - } + } } } } //#endif - + // For each installed type, get a list of the supported apps, and // verify that the list matches the list we generated. Also check // that the list of apps for the type's supertype (if it exists) @@ -2679,7 +2679,7 @@ MimeTypeTest::SupportingAppsTest() { CHK(mime.InitCheck() == B_OK); // printf("------------------------------------------------------------\n"); // printf("%s\n", type.c_str()); - + // Get the set of supporting apps for this type (and its supertype, if // it's not a supertype itself) that we discovered by manually culling // the database @@ -2687,7 +2687,7 @@ MimeTypeTest::SupportingAppsTest() { BMimeType superType; if (mime.GetSupertype(&superType) == B_OK) appSetSuper = typeAppMap[superType.Type()]; // Copy the supertype -/* +/* printf("sub.size == %ld\n", appSet.size()); std::set::iterator i; for (i = appSet.begin(); i != appSet.end(); i++) { @@ -2710,14 +2710,14 @@ MimeTypeTest::SupportingAppsTest() { std::queue appList; QueueAdapter appAdapter(appList); FillWithMimeTypes(appAdapter, msg, "applications"); - + // msg.PrintToStream(); - - + + } } } - + void MimeTypeTest::WildcardAppsTest() { // NULL param @@ -2726,14 +2726,14 @@ MimeTypeTest::WildcardAppsTest() { #if TEST_R5 CHK(BMimeType::GetWildcardApps(NULL) == B_OK); // R5 == B_OK (???) #else - CHK(BMimeType::GetWildcardApps(NULL) == B_BAD_VALUE); + CHK(BMimeType::GetWildcardApps(NULL) == B_BAD_VALUE); #endif } // Normal function (compare to BMimeType("application/octet-stream").GetSupportingApps()) NextSubTest(); { BMessage msg1, msg2; - CHK(BMimeType::GetWildcardApps(&msg1) == B_OK); + CHK(BMimeType::GetWildcardApps(&msg1) == B_OK); BMimeType mime(wildcardType); CHK(mime.InitCheck() == B_OK); CHK(mime.GetSupportingApps(&msg2) == B_OK); @@ -2837,7 +2837,7 @@ MimeTypeTest::InitTest() CHK(type.InitCheck() == B_NO_INIT); CHK(type.Type() == NULL); } - + // SetTo() // valid type NextSubTest(); @@ -2929,7 +2929,7 @@ MimeTypeTest::InitTest() CHK(type.InitCheck() == B_NO_INIT); CHK(type.Type() == NULL); } - + // reinitialization NextSubTest(); { @@ -3187,7 +3187,7 @@ MimeTypeTest::MonitoringTest() // tests: // * Start/StopWatching() // * updates - + // test: // * StartWatching() // * change something, check message queue (not empty) @@ -3544,7 +3544,7 @@ MimeTypeTest::UpdateMimeInfoTest() // cout << "begin..." << endl; // CHK(update_mime_info(NULL, true, true, false) == B_OK); // cout << "end..." << endl; - + // tests: // * update_mime_info() @@ -3835,7 +3835,7 @@ public: if (!buffer) error = B_NO_MEMORY; } - if (!error) + if (!error) error = msg.Flatten(buffer, msg.FlattenedSize()); if (!error) error = resources.AddResource(B_MESSAGE_TYPE, 1, buffer, @@ -4159,7 +4159,7 @@ MimeTypeTest::CreateAppMetaMimeTest() // non-existing file CHK(create_app_meta_mime(files[0].name.c_str(), false, true, false) == B_OK); - + } // CheckIconData @@ -4300,10 +4300,10 @@ MimeTypeTest::SnifferRuleTest() // not invalid priorities. Thus our checker chokes on these rules, // whilest R5's does not #if TEST_R5 - { "1E25 ('ABCD')", NULL }, + { "1E25 ('ABCD')", NULL }, { "1e25 ('ABCD')", NULL }, #else - { "1E25 ('ABCD')", "Sniffer pattern error: invalid priority" }, + { "1E25 ('ABCD')", "Sniffer pattern error: invalid priority" }, { "1e25 ('ABCD')", "Sniffer pattern error: invalid priority" }, #endif @@ -4377,7 +4377,7 @@ MimeTypeTest::SnifferRuleTest() "Sniffer pattern error: missing pattern" #endif }, - { "0.5 [0:3] ('ABCD' | 'abcd' | [13] 'EFGH')", + { "0.5 [0:3] ('ABCD' | 'abcd' | [13] 'EFGH')", "Sniffer pattern error: missing pattern" }, { "0.5('ABCD'|'abcd'|[13]'EFGH')", "Sniffer pattern error: missing pattern" }, @@ -4426,7 +4426,7 @@ MimeTypeTest::SnifferRuleTest() "Sniffer pattern error: expecting '|', ')', or possibly '&'" #endif }, - + // Miscellaneous tests designed to hit every remaining // relevant "throw new Err()" statement in our scanner. // R5 versions may come later, but I don't really see any @@ -4451,7 +4451,7 @@ MimeTypeTest::SnifferRuleTest() { "+1.e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.0e", "Sniffer pattern error: incomplete extended-notation floating point number" }, - + { "0.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { ".0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, @@ -4463,7 +4463,7 @@ MimeTypeTest::SnifferRuleTest() { "+1.e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "-1.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "+1.0e-", "Sniffer pattern error: incomplete extended-notation floating point number" }, - + { "0.0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { "1.0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, { ".0e+", "Sniffer pattern error: incomplete extended-notation floating point number" }, @@ -4481,20 +4481,20 @@ MimeTypeTest::SnifferRuleTest() { "'Escape!! \\", "Sniffer pattern error: incomplete escape sequence" }, { "\\x", "Sniffer pattern error: incomplete escaped hex code" }, - { "\\xNotAHexCode", "Sniffer pattern error: incomplete escaped hex code" }, + { "\\xNotAHexCode", "Sniffer pattern error: incomplete escaped hex code" }, { "\\xAlsoNotAHexCode", "Sniffer pattern error: incomplete escaped hex code" }, { "\\x0", "Sniffer pattern error: incomplete escaped hex code" }, - + { "1.0 (\\377)", NULL }, { "\\400", "Sniffer pattern error: invalid octal literal (octals must be between octal 0 and octal 377 inclusive)" }, { "\\777", "Sniffer pattern error: invalid octal literal (octals must be between octal 0 and octal 377 inclusive)" }, { "1.0 (\\800)", NULL }, - + { NULL, "Sniffer pattern error: NULL pattern" }, { "-2", "Sniffer pattern error: invalid priority" }, { "+2", "Sniffer pattern error: invalid priority" }, - + { "1.0", "Sniffer pattern error: missing expression" }, #endif // !TEST_R5 @@ -4507,7 +4507,7 @@ MimeTypeTest::SnifferRuleTest() // { "1E-25 ('ABCD')", NULL }, #endif }; - + const int testCaseCount = sizeof(testCases) / sizeof(test_case); BMimeType type; CHK(type.SetTo(testType) == B_OK); @@ -4645,7 +4645,7 @@ public: if (!error && metaType.length() > 0) { error = file.WriteAttr("META:TYPE", B_STRING_TYPE, 0, metaType.c_str(), metaType.length()+1); - error = error == (ssize_t)(metaType.length()+1) ? B_OK : error; + error = error == (ssize_t)(metaType.length()+1) ? B_OK : error; } return error; } @@ -4795,7 +4795,7 @@ printf("type: %s, should be: %s (file == '%s')\n", type.Type(), realType, filena #endif // abstract entry_ref CHK(get_ref_for_path(filename.c_str(), &ref) == B_OK); - // R5: B_NAME_NOT_FOUND, OBOS: + // R5: B_NAME_NOT_FOUND, OBOS: CHK(BMimeType::GuessMimeType(&ref, &type) != B_OK); } diff --git a/src/tests/kits/storage/MimeTypeTest.h b/src/tests/kits/storage/MimeTypeTest.h index 6713e546d4..b22a9fc196 100644 --- a/src/tests/kits/storage/MimeTypeTest.h +++ b/src/tests/kits/storage/MimeTypeTest.h @@ -23,10 +23,10 @@ class NotificationMessage; class MimeTypeTest : public BasicTest { public: static CppUnit::Test* Suite(); - + // This function called before *each* test added in Suite() void setUp(); - + // This function called after *each* test added in Suite() void tearDown(); @@ -48,7 +48,7 @@ public: void SupportingAppsTest(); void SupportedTypesTest(); void WildcardAppsTest(); - + void InitTest(); void StringTest(); void MonitoringTest();