vfs: check userland buffers before reading them.
[haiku.git] / src / kits / app / RosterPrivate.cpp
blob520e8ab4de62e0fc97f086f3ba96ab93115c4597
1 /*
2 * Copyright 2001-2015, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold (bonefish@users.sf.net)
7 */
10 //! Access class for BRoster members
13 #include <RosterPrivate.h>
15 #include <Roster.h>
17 #include <locks.h>
20 /*! \class BRoster::Private
21 \brief Class used to access private BRoster members.
23 This way, the only friend BRoster needs is this class.
27 /*! \brief Initializes the roster.
29 \param mainMessenger A BMessenger targeting the registrar application.
30 \param mimeMessenger A BMessenger targeting the MIME manager.
32 void
33 BRoster::Private::SetTo(BMessenger mainMessenger, BMessenger mimeMessenger)
35 if (fRoster != NULL) {
36 fRoster->fMessenger = mainMessenger;
37 fRoster->fMimeMessenger = mimeMessenger;
38 fRoster->fMimeMessengerInitOnce = INIT_ONCE_INITIALIZED;
43 /*! \brief Sends a message to the registrar.
45 \a mime specifies whether to send the message to the roster or to the
46 MIME data base service.
47 If \a reply is not \c NULL, the function waits for a reply.
49 \param message The message to be sent.
50 \param reply A pointer to a pre-allocated BMessage into which the reply
51 message will be copied. May be \c NULL.
52 \param mime \c true, if the message should be sent to the MIME data base
53 service, \c false for the roster.
54 \return
55 - \c B_OK: Everything went fine.
56 - \c B_BAD_VALUE: \c NULL \a message.
57 - \c B_NO_INIT: the roster is \c NULL.
58 - another error code
60 status_t
61 BRoster::Private::SendTo(BMessage *message, BMessage *reply, bool mime)
63 if (message == NULL)
64 return B_BAD_VALUE;
65 if (fRoster == NULL)
66 return B_NO_INIT;
68 const BMessenger& messenger = mime
69 ? fRoster->_MimeMessenger() : fRoster->fMessenger;
70 if (messenger.IsTargetLocal())
71 return B_BAD_VALUE;
73 return reply != NULL
74 ? messenger.SendMessage(message, reply)
75 : messenger.SendMessage(message);
79 /*! \brief Returns whether the roster's messengers are valid.
81 \a mime specifies whether to check the roster messenger or the one of
82 the MIME data base service.
84 \param mime \c true, if the MIME data base service messenger should be
85 checked, \c false for the roster messenger.
86 \return \true, if the selected messenger is valid, \c false otherwise.
88 bool
89 BRoster::Private::IsMessengerValid(bool mime) const
91 return fRoster != NULL && (mime ? fRoster->_MimeMessenger().IsValid()
92 : fRoster->fMessenger.IsValid());
96 /*! \brief Initializes the global be_roster variable.
98 Called before the global constructors are invoked.
100 void
101 BRoster::Private::InitBeRoster()
103 be_roster = new BRoster;
107 /*! \brief Deletes the global be_roster.
109 Called after the global destructors are invoked.
111 void
112 BRoster::Private::DeleteBeRoster()
114 delete be_roster;