2 * Copyright 2002-2006 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
8 * Ingo Weinhold, bonefish@users.sf.net
15 #include <mime/database_support.h>
16 #include <mime/DatabaseLocation.h>
17 #include <sniffer/Rule.h>
18 #include <sniffer/Parser.h>
20 #include <RegistrarDefs.h>
21 #include <RosterPrivate.h>
29 using namespace BPrivate
;
31 // Private helper functions
32 static bool isValidMimeChar(const char ch
);
34 using namespace BPrivate::Storage::Mime
;
37 const char* B_PEF_APP_MIME_TYPE
= "application/x-be-executable";
38 const char* B_PE_APP_MIME_TYPE
= "application/x-vnd.Be-peexecutable";
39 const char* B_ELF_APP_MIME_TYPE
= "application/x-vnd.Be-elfexecutable";
40 const char* B_RESOURCE_MIME_TYPE
= "application/x-be-resource";
41 const char* B_FILE_MIME_TYPE
= "application/octet-stream";
42 // Might be defined platform depended, but ELF will certainly be the common
43 // format for all platforms anyway.
44 const char* B_APP_MIME_TYPE
= B_ELF_APP_MIME_TYPE
;
48 isValidMimeChar(const char ch
)
50 // Handles white space and most CTLs
74 // Creates an uninitialized BMimeType object.
75 BMimeType::BMimeType()
83 // Creates a BMimeType object and initializes it to the supplied
85 BMimeType::BMimeType(const char* mimeType
)
94 // Frees all resources associated with this object.
95 BMimeType::~BMimeType()
101 // Initializes this object to the supplied MIME type.
103 BMimeType::SetTo(const char* mimeType
)
105 if (mimeType
== NULL
) {
107 } else if (!BMimeType::IsValid(mimeType
)) {
108 fCStatus
= B_BAD_VALUE
;
111 fType
= new(std::nothrow
) char[strlen(mimeType
) + 1];
113 strlcpy(fType
, mimeType
, B_MIME_TYPE_LENGTH
);
116 fCStatus
= B_NO_MEMORY
;
123 // Returns the object to an uninitialized state
129 fCStatus
= B_NO_INIT
;
133 // Returns the result of the most recent constructor or SetTo() call
135 BMimeType::InitCheck() const
141 // Returns the MIME string represented by this object
143 BMimeType::Type() const
149 // Returns whether the object represents a valid MIME type
151 BMimeType::IsValid() const
153 return InitCheck() == B_OK
&& BMimeType::IsValid(Type());
157 // Returns whether this objects represents a supertype
159 BMimeType::IsSupertypeOnly() const
161 if (fCStatus
== B_OK
) {
162 // We assume here fCStatus will be B_OK *only* if
163 // the MIME string is valid
164 size_t len
= strlen(fType
);
165 for (size_t i
= 0; i
< len
; i
++) {
175 // Returns whether or not this type is currently installed in the
178 BMimeType::IsInstalled() const
180 return InitCheck() == B_OK
181 && default_database_location()->IsInstalled(Type());
185 // Gets the supertype of the MIME type represented by this object
187 BMimeType::GetSupertype(BMimeType
* supertype
) const
189 if (supertype
== NULL
)
193 status_t status
= fCStatus
== B_OK
? B_OK
: B_BAD_VALUE
;
194 if (status
== B_OK
) {
195 size_t len
= strlen(fType
);
197 for (; i
< len
; i
++) {
202 // object is a supertype only
203 status
= B_BAD_VALUE
;
205 char superMime
[B_MIME_TYPE_LENGTH
];
206 strncpy(superMime
, fType
, i
);
208 status
= supertype
->SetTo(superMime
) == B_OK
? B_OK
: B_BAD_VALUE
;
216 // Returns whether this and the supplied MIME type are equal
218 BMimeType::operator==(const BMimeType
&type
) const
220 if (InitCheck() == B_NO_INIT
&& type
.InitCheck() == B_NO_INIT
)
222 else if (InitCheck() == B_OK
&& type
.InitCheck() == B_OK
)
223 return strcasecmp(Type(), type
.Type()) == 0;
229 // Returns whether this and the supplied MIME type are equal
231 BMimeType::operator==(const char* type
) const
237 return (*this) == mime
;
241 // Returns whether this MIME type is a supertype of or equals the
244 BMimeType::Contains(const BMimeType
* type
) const
253 if (type
->GetSupertype(&super
) == B_OK
&& *this == super
)
259 // Adds the MIME type to the MIME database
263 status_t err
= InitCheck();
265 BMessage
message(B_REG_MIME_INSTALL
);
269 // Build and send the message, read the reply
271 err
= message
.AddString("type", Type());
274 err
= BRoster::Private().SendTo(&message
, &reply
, true);
277 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
280 err
= reply
.FindInt32("result", &result
);
289 // Removes the MIME type from the MIME database
293 status_t err
= InitCheck();
295 BMessage
message(B_REG_MIME_DELETE
);
299 // Build and send the message, read the reply
301 err
= message
.AddString("type", Type());
304 err
= BRoster::Private().SendTo(&message
, &reply
, true);
307 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
310 err
= reply
.FindInt32("result", &result
);
319 // Fetches the large or mini icon associated with the MIME type
321 BMimeType::GetIcon(BBitmap
* icon
, icon_size size
) const
326 status_t err
= InitCheck();
328 err
= default_database_location()->GetIcon(Type(), *icon
, size
);
334 // Fetches the vector icon associated with the MIME type
336 BMimeType::GetIcon(uint8
** data
, size_t* size
) const
338 if (data
== NULL
|| size
== NULL
)
341 status_t err
= InitCheck();
343 err
= default_database_location()->GetIcon(Type(), *data
, *size
);
349 // Fetches the signature of the MIME type's preferred application from the
352 BMimeType::GetPreferredApp(char* signature
, app_verb verb
) const
354 status_t err
= InitCheck();
356 err
= default_database_location()->GetPreferredApp(Type(), signature
,
364 // Fetches from the MIME database a BMessage describing the attributes
365 // typically associated with files of the given MIME type
367 BMimeType::GetAttrInfo(BMessage
* info
) const
372 status_t err
= InitCheck();
374 err
= default_database_location()->GetAttributesInfo(Type(), *info
);
380 // Fetches the MIME type's associated filename extensions from the MIME
383 BMimeType::GetFileExtensions(BMessage
* extensions
) const
385 if (extensions
== NULL
)
388 status_t err
= InitCheck();
390 err
= default_database_location()->GetFileExtensions(Type(),
398 // Fetches the MIME type's short description from the MIME database
400 BMimeType::GetShortDescription(char* description
) const
402 status_t err
= InitCheck();
404 err
= default_database_location()->GetShortDescription(Type(),
412 // Fetches the MIME type's long description from the MIME database
414 BMimeType::GetLongDescription(char* description
) const
416 status_t err
= InitCheck();
418 err
= default_database_location()->GetLongDescription(Type(),
426 // Fetches a \c BMessage containing a list of MIME signatures of
427 // applications that are able to handle files of this MIME type.
429 BMimeType::GetSupportingApps(BMessage
* signatures
) const
431 if (signatures
== NULL
)
434 BMessage
message(B_REG_MIME_GET_SUPPORTING_APPS
);
437 status_t err
= InitCheck();
439 err
= message
.AddString("type", Type());
441 err
= BRoster::Private().SendTo(&message
, signatures
, true);
443 err
= (status_t
)(signatures
->what
== B_REG_RESULT
? B_OK
447 err
= signatures
->FindInt32("result", &result
);
455 // Sets the large or mini icon for the MIME type
457 BMimeType::SetIcon(const BBitmap
* icon
, icon_size which
)
459 return SetIconForType(NULL
, icon
, which
);
463 // Sets the vector icon for the MIME type
465 BMimeType::SetIcon(const uint8
* data
, size_t size
)
467 return SetIconForType(NULL
, data
, size
);
471 // Sets the preferred application for the MIME type
473 BMimeType::SetPreferredApp(const char* signature
, app_verb verb
)
475 status_t err
= InitCheck();
477 BMessage
message(signature
&& signature
[0]
478 ? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
482 // Build and send the message, read the reply
484 err
= message
.AddString("type", Type());
487 err
= message
.AddInt32("which", B_REG_MIME_PREFERRED_APP
);
489 if (err
== B_OK
&& signature
!= NULL
)
490 err
= message
.AddString("signature", signature
);
493 err
= message
.AddInt32("app verb", verb
);
496 err
= BRoster::Private().SendTo(&message
, &reply
, true);
499 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
502 err
= reply
.FindInt32("result", &result
);
511 // Sets the description of the attributes typically associated with files
512 // of the given MIME type
514 BMimeType::SetAttrInfo(const BMessage
* info
)
516 status_t err
= InitCheck();
518 BMessage
message(info
? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
522 // Build and send the message, read the reply
524 err
= message
.AddString("type", Type());
526 err
= message
.AddInt32("which", B_REG_MIME_ATTR_INFO
);
527 if (err
== B_OK
&& info
!= NULL
)
528 err
= message
.AddMessage("attr info", info
);
530 err
= BRoster::Private().SendTo(&message
, &reply
, true);
532 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
534 err
= reply
.FindInt32("result", &result
);
542 // Sets the list of filename extensions associated with the MIME type
544 BMimeType::SetFileExtensions(const BMessage
* extensions
)
546 status_t err
= InitCheck();
548 BMessage
message(extensions
? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
552 // Build and send the message, read the reply
554 err
= message
.AddString("type", Type());
557 err
= message
.AddInt32("which", B_REG_MIME_FILE_EXTENSIONS
);
559 if (err
== B_OK
&& extensions
!= NULL
)
560 err
= message
.AddMessage("extensions", extensions
);
563 err
= BRoster::Private().SendTo(&message
, &reply
, true);
566 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
569 err
= reply
.FindInt32("result", &result
);
578 // Sets the short description field for the MIME type
580 BMimeType::SetShortDescription(const char* description
)
582 status_t err
= InitCheck();
584 BMessage
message(description
&& description
[0]
585 ? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
589 // Build and send the message, read the reply
591 err
= message
.AddString("type", Type());
594 err
= message
.AddInt32("which", B_REG_MIME_DESCRIPTION
);
596 if (err
== B_OK
&& description
)
597 err
= message
.AddString("description", description
);
600 err
= message
.AddBool("long", false);
603 err
= BRoster::Private().SendTo(&message
, &reply
, true);
606 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
609 err
= reply
.FindInt32("result", &result
);
618 // Sets the long description field for the MIME type
620 BMimeType::SetLongDescription(const char* description
)
622 status_t err
= InitCheck();
624 BMessage
message(description
&& description
[0]
625 ? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
629 // Build and send the message, read the reply
631 err
= message
.AddString("type", Type());
634 err
= message
.AddInt32("which", B_REG_MIME_DESCRIPTION
);
636 if (err
== B_OK
&& description
)
637 err
= message
.AddString("description", description
);
640 err
= message
.AddBool("long", true);
643 err
= BRoster::Private().SendTo(&message
, &reply
, true);
646 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
649 err
= reply
.FindInt32("result", &result
);
658 // Fetches a BMessage listing all the MIME supertypes currently
659 // installed in the MIME database.
661 BMimeType::GetInstalledSupertypes(BMessage
* supertypes
)
663 if (supertypes
== NULL
)
666 BMessage
message(B_REG_MIME_GET_INSTALLED_SUPERTYPES
);
669 status_t err
= BRoster::Private().SendTo(&message
, supertypes
, true);
671 err
= (status_t
)(supertypes
->what
== B_REG_RESULT
? B_OK
675 err
= supertypes
->FindInt32("result", &result
);
683 // Fetches a BMessage listing all the MIME types currently installed
684 // in the MIME database.
686 BMimeType::GetInstalledTypes(BMessage
* types
)
688 return GetInstalledTypes(NULL
, types
);
692 // Fetches a BMessage listing all the MIME subtypes of the given
693 // supertype currently installed in the MIME database.
695 BMimeType::GetInstalledTypes(const char* supertype
, BMessage
* types
)
702 // Build and send the message, read the reply
703 BMessage
message(B_REG_MIME_GET_INSTALLED_TYPES
);
706 if (supertype
!= NULL
)
707 err
= message
.AddString("supertype", supertype
);
709 err
= BRoster::Private().SendTo(&message
, types
, true);
711 err
= (status_t
)(types
->what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
713 err
= types
->FindInt32("result", &result
);
721 // Fetches a \c BMessage containing a list of MIME signatures of
722 // applications that are able to handle files of any type.
724 BMimeType::GetWildcardApps(BMessage
* wild_ones
)
727 status_t err
= mime
.SetTo("application/octet-stream");
729 err
= mime
.GetSupportingApps(wild_ones
);
734 // Returns whether the given string represents a valid MIME type.
736 BMimeType::IsValid(const char* string
)
741 bool foundSlash
= false;
742 size_t len
= strlen(string
);
743 if (len
>= B_MIME_TYPE_LENGTH
|| len
== 0)
746 for (size_t i
= 0; i
< len
; i
++) {
749 if (foundSlash
|| i
== 0 || i
== len
- 1)
753 } else if (!isValidMimeChar(ch
)) {
761 // Fetches an \c entry_ref that serves as a hint as to where the MIME type's
762 // preferred application might live
764 BMimeType::GetAppHint(entry_ref
* ref
) const
769 status_t err
= InitCheck();
771 err
= default_database_location()->GetAppHint(Type(), *ref
);
776 // Sets the app hint field for the MIME type
778 BMimeType::SetAppHint(const entry_ref
* ref
)
780 status_t err
= InitCheck();
782 BMessage
message(ref
? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
786 // Build and send the message, read the reply
788 err
= message
.AddString("type", Type());
791 err
= message
.AddInt32("which", B_REG_MIME_APP_HINT
);
793 if (err
== B_OK
&& ref
!= NULL
)
794 err
= message
.AddRef("app hint", ref
);
797 err
= BRoster::Private().SendTo(&message
, &reply
, true);
800 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
803 err
= reply
.FindInt32("result", &result
);
812 // Fetches the large or mini icon used by an application of this type for
813 // files of the given type.
815 BMimeType::GetIconForType(const char* type
, BBitmap
* icon
, icon_size which
) const
820 // If type is NULL, this function works just like GetIcon(), othewise,
821 // we need to make sure the give type is valid.
824 err
= BMimeType::IsValid(type
) ? B_OK
: B_BAD_VALUE
;
826 err
= default_database_location()->GetIconForType(Type(), type
,
830 err
= GetIcon(icon
, which
);
836 // Fetches the vector icon used by an application of this type for files of
839 BMimeType::GetIconForType(const char* type
, uint8
** _data
, size_t* _size
) const
841 if (_data
== NULL
|| _size
== NULL
)
844 // If type is NULL, this function works just like GetIcon(), otherwise,
845 // we need to make sure the give type is valid.
847 return GetIcon(_data
, _size
);
849 if (!BMimeType::IsValid(type
))
852 return default_database_location()->GetIconForType(Type(), type
, *_data
,
857 // Sets the large or mini icon used by an application of this type for
858 // files of the given type.
860 BMimeType::SetIconForType(const char* type
, const BBitmap
* icon
, icon_size which
)
862 status_t err
= InitCheck();
864 BMessage
message(icon
? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
871 // Build and send the message, read the reply
873 err
= message
.AddString("type", Type());
876 err
= message
.AddInt32("which",
877 type
? B_REG_MIME_ICON_FOR_TYPE
: B_REG_MIME_ICON
);
882 err
= get_icon_data(icon
, which
, &data
, &dataSize
);
885 err
= message
.AddData("icon data", B_RAW_TYPE
, data
, dataSize
);
889 err
= message
.AddInt32("icon size", which
);
893 err
= BMimeType::IsValid(type
) ? B_OK
: B_BAD_VALUE
;
896 err
= message
.AddString("file type", type
);
900 err
= BRoster::Private().SendTo(&message
, &reply
, true);
903 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
906 err
= reply
.FindInt32("result", &result
);
911 delete[] (int8
*)data
;
917 // Sets the large or mini icon used by an application of this type for
918 // files of the given type.
920 BMimeType::SetIconForType(const char* type
, const uint8
* data
, size_t dataSize
)
922 status_t err
= InitCheck();
924 BMessage
message(data
? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
928 // Build and send the message, read the reply
930 err
= message
.AddString("type", Type());
932 err
= message
.AddInt32("which", (type
? B_REG_MIME_ICON_FOR_TYPE
: B_REG_MIME_ICON
));
935 err
= message
.AddData("icon data", B_RAW_TYPE
, data
, dataSize
);
938 err
= message
.AddInt32("icon size", -1);
939 // -1 indicates size should be ignored (vector icon data)
942 err
= BMimeType::IsValid(type
) ? B_OK
: B_BAD_VALUE
;
944 err
= message
.AddString("file type", type
);
947 err
= BRoster::Private().SendTo(&message
, &reply
, true);
949 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
951 err
= reply
.FindInt32("result", &result
);
959 // Retrieves the MIME type's sniffer rule
961 BMimeType::GetSnifferRule(BString
* result
) const
966 status_t err
= InitCheck();
968 err
= default_database_location()->GetSnifferRule(Type(), *result
);
974 // Sets the MIME type's sniffer rule
976 BMimeType::SetSnifferRule(const char* rule
)
978 status_t err
= InitCheck();
979 if (err
== B_OK
&& rule
!= NULL
&& rule
[0] != '\0')
980 err
= CheckSnifferRule(rule
, NULL
);
985 BMessage
message(rule
&& rule
[0] ? B_REG_MIME_SET_PARAM
986 : B_REG_MIME_DELETE_PARAM
);
990 // Build and send the message, read the reply
991 err
= message
.AddString("type", Type());
993 err
= message
.AddInt32("which", B_REG_MIME_SNIFFER_RULE
);
995 if (err
== B_OK
&& rule
)
996 err
= message
.AddString("sniffer rule", rule
);
999 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1002 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1005 err
= reply
.FindInt32("result", &result
);
1014 // Checks whether a MIME sniffer rule is valid or not.
1016 BMimeType::CheckSnifferRule(const char* rule
, BString
* parseError
)
1018 BPrivate::Storage::Sniffer::Rule snifferRule
;
1020 return BPrivate::Storage::Sniffer::parse(rule
, &snifferRule
, parseError
);
1024 // Guesses a MIME type for the entry referred to by the given
1027 BMimeType::GuessMimeType(const entry_ref
* file
, BMimeType
* type
)
1029 status_t err
= file
&& type
? B_OK
: B_BAD_VALUE
;
1031 BMessage
message(B_REG_MIME_SNIFF
);
1036 // Build and send the message, read the reply
1038 err
= message
.AddRef("file ref", file
);
1041 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1044 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1047 err
= reply
.FindInt32("result", &result
);
1053 err
= reply
.FindString("mime type", &str
);
1056 err
= type
->SetTo(str
);
1062 // Guesses a MIME type for the supplied chunk of data.
1064 BMimeType::GuessMimeType(const void* buffer
, int32 length
, BMimeType
* type
)
1066 status_t err
= buffer
&& type
? B_OK
: B_BAD_VALUE
;
1068 BMessage
message(B_REG_MIME_SNIFF
);
1073 // Build and send the message, read the reply
1075 err
= message
.AddData("data", B_RAW_TYPE
, buffer
, length
);
1078 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1081 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1084 err
= reply
.FindInt32("result", &result
);
1090 err
= reply
.FindString("mime type", &str
);
1093 err
= type
->SetTo(str
);
1099 // Guesses a MIME type for the given filename.
1101 BMimeType::GuessMimeType(const char* filename
, BMimeType
* type
)
1103 status_t err
= filename
&& type
? B_OK
: B_BAD_VALUE
;
1105 BMessage
message(B_REG_MIME_SNIFF
);
1110 // Build and send the message, read the reply
1112 err
= message
.AddString("filename", filename
);
1115 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1118 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1121 err
= reply
.FindInt32("result", &result
);
1127 err
= reply
.FindString("mime type", &str
);
1130 err
= type
->SetTo(str
);
1136 // Starts monitoring the MIME database for a given target.
1138 BMimeType::StartWatching(BMessenger target
)
1140 BMessage
message(B_REG_MIME_START_WATCHING
);
1145 // Build and send the message, read the reply
1146 err
= message
.AddMessenger("target", target
);
1148 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1151 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1154 err
= reply
.FindInt32("result", &result
);
1163 // Stops monitoring the MIME database for a given target
1165 BMimeType::StopWatching(BMessenger target
)
1167 BMessage
message(B_REG_MIME_STOP_WATCHING
);
1172 // Build and send the message, read the reply
1173 err
= message
.AddMessenger("target", target
);
1175 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1178 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1181 err
= reply
.FindInt32("result", &result
);
1190 // Initializes this object to the supplied MIME type
1192 BMimeType::SetType(const char* mimeType
)
1194 return SetTo(mimeType
);
1198 void BMimeType::_ReservedMimeType1() {}
1199 void BMimeType::_ReservedMimeType2() {}
1200 void BMimeType::_ReservedMimeType3() {}
1203 // assignment operator.
1206 BMimeType::operator=(const BMimeType
&)
1215 BMimeType::BMimeType(const BMimeType
&)
1221 BMimeType::GetSupportedTypes(BMessage
* types
)
1226 status_t err
= InitCheck();
1228 err
= default_database_location()->GetSupportedTypes(Type(), *types
);
1234 /*! Sets the list of MIME types supported by the MIME type (which is
1235 assumed to be an application signature).
1237 If \a types is \c NULL the application's supported types are unset.
1239 The supported MIME types must be stored in a field "types" of type
1240 \c B_STRING_TYPE in \a types.
1242 For each supported type the result of BMimeType::GetSupportingApps() will
1243 afterwards include the signature of this application.
1245 \a fullSync specifies whether or not any types that are no longer
1246 listed as supported types as of this call to SetSupportedTypes() shall be
1247 updated as well, i.e. whether this application shall be removed from their
1248 lists of supporting applications.
1250 If \a fullSync is \c false, this application will not be removed from the
1251 previously supported types' supporting apps lists until the next call
1252 to BMimeType::SetSupportedTypes() or BMimeType::DeleteSupportedTypes()
1253 with a \c true \a fullSync parameter, the next call to BMimeType::Delete(),
1256 \param types The supported types to be assigned to the file.
1258 \param fullSync \c true to also synchronize the previously supported
1259 types, \c false otherwise.
1261 \returns \c B_OK on success or another error code on failure.
1264 BMimeType::SetSupportedTypes(const BMessage
* types
, bool fullSync
)
1266 status_t err
= InitCheck();
1268 // Build and send the message, read the reply
1269 BMessage
message(types
? B_REG_MIME_SET_PARAM
: B_REG_MIME_DELETE_PARAM
);
1274 err
= message
.AddString("type", Type());
1277 err
= message
.AddInt32("which", B_REG_MIME_SUPPORTED_TYPES
);
1279 if (err
!= B_OK
&& types
!= NULL
)
1280 err
= message
.AddMessage("types", types
);
1283 err
= message
.AddBool("full sync", fullSync
);
1286 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1289 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1292 err
= reply
.FindInt32("result", &result
);
1301 /*! Returns a list of mime types associated with the given file extension
1303 The list of types is returned in the pre-allocated \c BMessage pointed to
1304 by \a types. The types are stored in the message's "types" field, which
1305 is an array of \c B_STRING_TYPE values.
1307 \param extension The file extension of interest
1308 \param types Pointer to a pre-allocated BMessage into which the result will
1311 \returns \c B_OK on success or another error code on failure.
1314 BMimeType::GetAssociatedTypes(const char* extension
, BMessage
* types
)
1316 status_t err
= extension
&& types
? B_OK
: B_BAD_VALUE
;
1318 BMessage
message(B_REG_MIME_GET_ASSOCIATED_TYPES
);
1319 BMessage
&reply
= *types
;
1322 // Build and send the message, read the reply
1324 err
= message
.AddString("extension", extension
);
1327 err
= BRoster::Private().SendTo(&message
, &reply
, true);
1330 err
= (status_t
)(reply
.what
== B_REG_RESULT
? B_OK
: B_BAD_REPLY
);
1333 err
= reply
.FindInt32("result", &result
);