vfs: check userland buffers before reading them.
[haiku.git] / src / kits / package / Request.cpp
blob07a68bc2b7eafc405da12fde6a68eb6c9822ad9c
1 /*
2 * Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Oliver Tappe <zooey@hirschkaefer.de>
7 */
10 #include <package/Request.h>
12 #include <new>
14 #include <JobQueue.h>
16 #include <package/Context.h>
19 namespace BPackageKit {
22 using BSupportKit::BPrivate::JobQueue;
25 BRequest::BRequest(const BContext& context)
27 fContext(context),
28 fJobQueue(new (std::nothrow) JobQueue())
30 fInitStatus = fJobQueue == NULL ? B_NO_MEMORY : B_OK;
34 BRequest::~BRequest()
39 status_t
40 BRequest::InitCheck() const
42 return fInitStatus;
46 BSupportKit::BJob*
47 BRequest::PopRunnableJob()
49 if (fJobQueue == NULL)
50 return NULL;
52 return fJobQueue->Pop();
56 status_t
57 BRequest::Process(bool failIfCanceledOnly)
59 status_t error = InitCheck();
60 if (error != B_OK)
61 return error;
63 error = CreateInitialJobs();
64 if (error != B_OK)
65 return error;
67 while (BSupportKit::BJob* job = PopRunnableJob()) {
68 error = job->Run();
69 delete job;
70 if (error != B_OK) {
71 if (!failIfCanceledOnly || error == B_CANCELED)
72 return error;
76 return B_OK;
80 status_t
81 BRequest::QueueJob(BSupportKit::BJob* job)
83 if (fJobQueue == NULL)
84 return B_NO_INIT;
86 job->AddStateListener(this);
87 job->AddStateListener(&fContext.JobStateListener());
89 return fJobQueue->AddJob(job);
93 } // namespace BPackageKit