vfs: check userland buffers before reading them.
[haiku.git] / src / servers / registrar / AppInfoListMessagingTargetSet.cpp
blobc872b2d31c319089f553fdbdf67f7bd46ccd413c
1 /*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
4 */
6 #include <Application.h>
7 #include <TokenSpace.h>
9 #include "AppInfoListMessagingTargetSet.h"
10 #include "RosterAppInfo.h"
12 // constructor
13 AppInfoListMessagingTargetSet::AppInfoListMessagingTargetSet(
14 AppInfoList &list, bool skipRegistrar)
15 : fList(list),
16 fIterator(list.It()),
17 fSkipRegistrar(skipRegistrar)
19 _SkipFilteredOutInfos();
22 // destructor
23 AppInfoListMessagingTargetSet::~AppInfoListMessagingTargetSet()
27 // HasNext
28 bool
29 AppInfoListMessagingTargetSet::HasNext() const
31 return fIterator.IsValid();
34 // Next
35 bool
36 AppInfoListMessagingTargetSet::Next(port_id &port, int32 &token)
38 if (!fIterator.IsValid())
39 return false;
41 port = (*fIterator)->port;
42 token = B_PREFERRED_TOKEN;
44 ++fIterator;
45 _SkipFilteredOutInfos();
47 return true;
50 // Rewind
51 void
52 AppInfoListMessagingTargetSet::Rewind()
54 fIterator = fList.It();
57 // Filter
58 bool
59 AppInfoListMessagingTargetSet::Filter(const RosterAppInfo *info)
61 if (!fSkipRegistrar)
62 return true;
64 return (!fSkipRegistrar || info->team != be_app->Team());
67 // _SkipFilteredOutInfos
68 void
69 AppInfoListMessagingTargetSet::_SkipFilteredOutInfos()
71 while (fIterator.IsValid() && !Filter(*fIterator))
72 ++fIterator;