hrev47402 adds 2 changesets to branch 'master' old head: d2d1af830b3f144937ea5e4c3f0e5b74c4c3d737 new head: b885e90eb96c5c2b629c81d35b7f9970db239995 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=b885e90+%5Ed2d1af8 ---------------------------------------------------------------------------- a30a4a4: Style fixes to Storage Kit classes. No functional changes intended. * Some variable renaming for clarity and consistency. * Pointer style fixes. * Added private method documentation back to cpp files for some methods. b885e90: Documentation updates for Storage Kit classes * Added \since to each method and parameter. * Whitespace cleanup. * Some other minor cleanups and updates. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- 41 files changed, 5067 insertions(+), 3076 deletions(-) docs/user/storage/AppFileInfo.dox | 341 +++---- docs/user/storage/Directory.dox | 190 ++-- docs/user/storage/Entry.dox | 245 +++-- docs/user/storage/EntryList.dox | 54 +- docs/user/storage/File.dox | 146 +-- docs/user/storage/FilePanel.dox | 140 ++- docs/user/storage/FindDirectory.dox | 1389 +++++++++++++++++++++------ docs/user/storage/Mime.dox | 150 ++- docs/user/storage/MimeType.dox | 592 +++++++----- docs/user/storage/Node.dox | 568 ++++++----- docs/user/storage/NodeInfo.dox | 116 ++- docs/user/storage/NodeMonitor.dox | 186 ++-- docs/user/storage/Path.dox | 105 +- docs/user/storage/PathFinder.dox | 264 ++--- docs/user/storage/Query.dox | 152 ++- docs/user/storage/Resources.dox | 96 +- docs/user/storage/Statable.dox | 82 +- docs/user/storage/SymLink.dox | 57 +- docs/user/storage/Volume.dox | 87 +- docs/user/storage/VolumeRoster.dox | 28 +- headers/os/storage/FindDirectory.h | 6 +- headers/os/storage/MimeType.h | 230 ++--- headers/os/storage/Node.h | 22 +- headers/os/storage/NodeInfo.h | 10 +- headers/os/storage/NodeMonitor.h | 41 +- headers/os/storage/Statable.h | 66 +- headers/os/storage/SymLink.h | 24 +- src/kits/storage/AppFileInfo.cpp | 75 ++ src/kits/storage/Entry.cpp | 65 ++ src/kits/storage/File.cpp | 9 +- src/kits/storage/Mime.cpp | 16 +- src/kits/storage/MimeType.cpp | 755 +++++++++------ src/kits/storage/Node.cpp | 302 ++++-- src/kits/storage/NodeInfo.cpp | 530 +++++----- src/kits/storage/NodeMonitor.cpp | 14 +- src/kits/storage/Path.cpp | 29 +- src/kits/storage/Query.cpp | 54 +- src/kits/storage/Statable.cpp | 257 ++--- src/kits/storage/SymLink.cpp | 34 +- src/tests/kits/storage/MimeTypeTest.cpp | 610 ++++++------ src/tests/kits/storage/MimeTypeTest.h | 6 +- ############################################################################ Commit: a30a4a41f948ebb03b95dab065a27a584ac0c97a URL: http://cgit.haiku-os.org/haiku/commit/?id=a30a4a4 Author: John Scipione <jscipione@xxxxxxxxx> Date: Wed Jun 18 23:07:02 2014 UTC Style fixes to Storage Kit classes. No functional changes intended. * Some variable renaming for clarity and consistency. * Pointer style fixes. * Added private method documentation back to cpp files for some methods. ---------------------------------------------------------------------------- diff --git a/headers/os/storage/FindDirectory.h b/headers/os/storage/FindDirectory.h index 4b74cfa..29b64cd 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 f82548c..ccd98fd 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 <File.h> #include <Entry.h> + 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(); - - 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; - - bool operator==(const BMimeType &type) const; - bool operator==(const char *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; - - 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); - - 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); - - /* 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); - - static status_t StartWatching(BMessenger target); - static status_t StopWatching(BMessenger target); - - /* 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/" - - friend class MimeTypeTest; - // for testing only - - friend class BAppFileInfo; - - virtual void _ReservedMimeType1(); - virtual void _ReservedMimeType2(); - virtual void _ReservedMimeType3(); - - BMimeType& operator=(const BMimeType& source); - BMimeType(const BMimeType& source); - - status_t GetSupportedTypes(BMessage* types); - status_t SetSupportedTypes(const BMessage* types, bool fullSync = true); - - 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]; +public: + BMimeType(); + BMimeType(const char* mimeType); + virtual ~BMimeType(); + + 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; + + bool operator==(const BMimeType &type) const; + bool operator==(const char* 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; + + 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); + + 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); + + /* 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); + + static status_t StartWatching(BMessenger target); + static status_t StopWatching(BMessenger target); + + /* 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/" + + friend class MimeTypeTest; + // for testing only + + friend class BAppFileInfo; + + virtual void _ReservedMimeType1(); + virtual void _ReservedMimeType2(); + virtual void _ReservedMimeType3(); + + BMimeType& operator=(const BMimeType& source); + BMimeType(const BMimeType& source); + + status_t GetSupportedTypes(BMessage* types); + status_t SetSupportedTypes(const BMessage* types, bool fullSync = true); + + 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]; }; + #endif // _MIME_TYPE_H diff --git a/headers/os/storage/Node.h b/headers/os/storage/Node.h index 618d4ae..5b28249 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 b82771c..64e05f2 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 cb66f15..12d8f0b 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 099e730..699ba0f 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 89d3798..e4b9600 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 85165b4..ef3ca1a 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 c078bee..5edab8c 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 5de2602..a3a0cea 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 c8c34e1a..aca9e25 100644 --- a/src/kits/storage/Mime.cpp +++ b/src/kits/storage/Mime.cpp @@ -8,10 +8,6 @@ * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx */ -/*! - \file Mime.cpp - Mime type C functions implementation. -*/ #include <errno.h> #include <new> @@ -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 b108421..4b4c350 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@xxxxxxxxxxxxxxxx * Tyler Dauwalder * Ingo Weinhold, bonefish@xxxxxxxxxxxx - * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx */ @@ -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 83ce9dc..5ecc21f 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); } [ *** diff truncated: 3987 lines dropped *** ] ############################################################################ Revision: hrev47402 Commit: b885e90eb96c5c2b629c81d35b7f9970db239995 URL: http://cgit.haiku-os.org/haiku/commit/?id=b885e90 Author: John Scipione <jscipione@xxxxxxxxx> Date: Wed Jun 18 23:10:45 2014 UTC Documentation updates for Storage Kit classes * Added \since to each method and parameter. * Whitespace cleanup. * Some other minor cleanups and updates. ----------------------------------------------------------------------------