Remove Curl, Switch to NetApi in Package Kit

Change-Id: I92213ab60dc987175c323d1d9ed11ac8b3517f2f
Reviewed-on: https://review.haiku-os.org/475
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
CodeforEvolution 2018-08-17 14:35:40 -04:00 committed by waddlesplash
parent 66f8dcb1f1
commit 106ae4ec35
9 changed files with 155 additions and 145 deletions

View File

@ -77,12 +77,6 @@ HPKG_SOURCES =
ReaderImplBaseV1.cpp
;
# TODO: remove this hack once gcc2 has -iquote implemented
if $(HOST_PLATFORM) = haiku_host && $(HOST_GCC_VERSION[1]) < 3 {
local locations = common/non-packaged common system ;
SourceHdrs FetchFileJob.cpp : /boot/$(locations)/develop/headers/curl ;
}
# locate the library
MakeLocate libpackage_build.so : $(HOST_BUILD_COMPATIBILITY_LIB_DIR) ;
@ -139,7 +133,7 @@ BuildPlatformSharedLibrary libpackage_build.so
SolverRepository.cpp
SolverResult.cpp
:
libshared_build.a $(HOST_LIBBE) curl $(HOST_LIBSTDC++)
libshared_build.a $(HOST_LIBBE) $(HOST_LIBSTDC++)
;
HaikuSubInclude solver ;

View File

@ -14,9 +14,10 @@
#include <Path.h>
#include <package/ActivateRepositoryConfigJob.h>
#include <package/FetchFileJob.h>
#include <package/PackageRoster.h>
#include "FetchFileJob.h"
namespace BPackageKit {

View File

@ -9,9 +9,10 @@
#include <package/DownloadFileRequest.h>
#include <package/FetchFileJob.h>
#include <package/ValidateChecksumJob.h>
#include "FetchFileJob.h"
namespace BPackageKit {

View File

@ -9,22 +9,26 @@
*/
#include <package/FetchFileJob.h>
#include "FetchFileJob.h"
#include <stdio.h>
#ifndef HAIKU_BOOTSTRAP_BUILD
#include <curl/curl.h>
#endif
#include <sys/wait.h>
#include <Path.h>
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
# include <UrlRequest.h>
# include <UrlProtocolRoster.h>
#endif
namespace BPackageKit {
namespace BPrivate {
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
FetchFileJob::FetchFileJob(const BContext& context, const BString& title,
const BString& fileURL, const BEntry& targetEntry)
:
@ -84,108 +88,74 @@ FetchFileJob::Execute()
if (result != B_OK)
return result;
#ifndef HAIKU_BOOTSTRAP_BUILD
CURL* handle = curl_easy_init();
BUrlRequest* request = BUrlProtocolRoster::MakeRequest(fFileURL.String(),
this);
thread_id thread = request->Run();
wait_for_thread(thread, NULL);
if (handle == NULL)
return B_NO_MEMORY;
#if LIBCURL_VERSION_MAJOR > 7 \
|| (LIBCURL_VERSION_MAJOR == 7 && LIBCURL_VERSION_MINOR >= 32)
result = curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0);
result = curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION,
&_TransferCallback);
if (result != CURLE_OK)
return B_BAD_VALUE;
#endif
result = curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, this);
if (result != CURLE_OK)
if (fSuccess == true)
return B_OK;
else
return B_ERROR;
result = curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION,
&_WriteCallback);
if (result != CURLE_OK)
return B_ERROR;
//TODO: More detailed error codes?
#if 0
const BHttpResult& outResult = dynamic_cast<const BHttpResult&>
(request->Result());
result = curl_easy_setopt(handle, CURLOPT_WRITEDATA, this);
if (result != CURLE_OK)
return B_ERROR;
result = curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
if (result != CURLE_OK)
return B_ERROR;
result = curl_easy_setopt(handle, CURLOPT_URL, fFileURL.String());
if (result != CURLE_OK)
return B_ERROR;
result = curl_easy_perform(handle);
curl_easy_cleanup(handle);
switch (result) {
case CURLE_OK:
switch (outResult.StatusCode()) {
case B_HTTP_STATUS_OK:
return B_OK;
case CURLE_UNSUPPORTED_PROTOCOL:
return EPROTONOSUPPORT;
case CURLE_FAILED_INIT:
return B_NO_INIT;
case CURLE_URL_MALFORMAT:
return B_BAD_VALUE;
case CURLE_NOT_BUILT_IN:
return B_NOT_SUPPORTED;
case CURLE_COULDNT_RESOLVE_PROXY:
case CURLE_COULDNT_RESOLVE_HOST:
return B_NAME_NOT_FOUND;
case CURLE_COULDNT_CONNECT:
return ECONNREFUSED;
case CURLE_FTP_WEIRD_SERVER_REPLY:
return B_BAD_DATA;
case CURLE_REMOTE_ACCESS_DENIED:
return B_NOT_ALLOWED;
case CURLE_PARTIAL_FILE:
case B_HTTP_STATUS_PARTIAL_CONTENT:
return B_PARTIAL_READ;
case CURLE_OUT_OF_MEMORY:
return B_NO_MEMORY;
case CURLE_OPERATION_TIMEDOUT:
case B_HTTP_STATUS_REQUEST_TIMEOUT:
case B_HTTP_STATUS_GATEWAY_TIMEOUT:
return B_TIMED_OUT;
case CURLE_SSL_CONNECT_ERROR:
return B_BAD_REPLY;
case B_HTTP_STATUS_NOT_IMPLEMENTED:
case B_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE:
return B_NOT_SUPPORTED;
case B_HTTP_STATUS_UNAUTHORIZED:
return B_PERMISSION_DENIED;
case B_HTTP_STATUS_FORBIDDEN:
case B_HTTP_STATUS_METHOD_NOT_ALLOWED:
case B_HTTP_STATUS_NOT_ACCEPTABLE:
return B_NOT_ALLOWED;
case B_HTTP_STATUS_NOT_FOUND:
return B_NAME_NOT_FOUND;
case B_HTTP_STATUS_BAD_GATEWAY:
return B_BAD_DATA;
default:
// TODO: map more curl error codes to ours for more
// precise error reporting
return B_ERROR;
}
#endif /* !HAIKU_BOOTSTRAP_BUILD */
return B_OK;
#endif
}
int
FetchFileJob::_TransferCallback(void* _job, off_t downloadTotal,
off_t downloaded, off_t uploadTotal, off_t uploaded)
void
FetchFileJob::DataReceived(BUrlRequest*, const char* data, off_t position,
ssize_t size)
{
FetchFileJob* job = reinterpret_cast<FetchFileJob*>(_job);
if (downloadTotal != 0) {
job->fBytes = downloaded;
job->fTotalBytes = downloadTotal;
job->fDownloadProgress = (float)downloaded / downloadTotal;
job->NotifyStateListeners();
fTargetFile.WriteAt(position, data, size);
}
void
FetchFileJob::DownloadProgress(BUrlRequest*, ssize_t bytesReceived,
ssize_t bytesTotal)
{
if (bytesTotal != 0) {
fBytes = bytesReceived;
fTotalBytes = bytesTotal;
fDownloadProgress = (float)bytesReceived/bytesTotal;
NotifyStateListeners();
}
return 0;
}
size_t
FetchFileJob::_WriteCallback(void *buffer, size_t size, size_t nmemb,
void *userp)
void
FetchFileJob::RequestCompleted(BUrlRequest*, bool success)
{
FetchFileJob* job = reinterpret_cast<FetchFileJob*>(userp);
ssize_t dataWritten = job->fTargetFile.Write(buffer, size * nmemb);
return size_t(dataWritten);
fSuccess = success;
}
@ -197,6 +167,78 @@ FetchFileJob::Cleanup(status_t jobResult)
}
#else // HAIKU_TARGET_PLATFORM_HAIKU
FetchFileJob::FetchFileJob(const BContext& context, const BString& title,
const BString& fileURL, const BEntry& targetEntry)
:
inherited(context, title),
fFileURL(fileURL),
fTargetEntry(targetEntry),
fTargetFile(&targetEntry, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY),
fDownloadProgress(0.0)
{
}
FetchFileJob::~FetchFileJob()
{
}
float
FetchFileJob::DownloadProgress() const
{
return fDownloadProgress;
}
const char*
FetchFileJob::DownloadURL() const
{
return fFileURL.String();
}
const char*
FetchFileJob::DownloadFileName() const
{
return fTargetEntry.Name();
}
off_t
FetchFileJob::DownloadBytes() const
{
return fBytes;
}
off_t
FetchFileJob::DownloadTotalBytes() const
{
return fTotalBytes;
}
status_t
FetchFileJob::Execute()
{
return B_UNSUPPORTED;
}
void
FetchFileJob::Cleanup(status_t jobResult)
{
if (jobResult != B_OK)
fTargetEntry.Remove();
}
#endif // HAIKU_TARGET_PLATFORM_HAIKU
} // namespace BPrivate
} // namespace BPackageKit

View File

@ -12,6 +12,10 @@
#include <File.h>
#include <String.h>
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
# include <UrlProtocolListener.h>
#endif
#include <package/Job.h>
@ -20,7 +24,12 @@ namespace BPackageKit {
namespace BPrivate {
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
class FetchFileJob : public BJob, public BUrlProtocolListener {
#else // HAIKU_TARGET_PLATFORM_HAIKU
class FetchFileJob : public BJob {
#endif // HAIKU_TARGET_PLATFORM_HAIKU
typedef BJob inherited;
public:
@ -36,23 +45,23 @@ public:
off_t DownloadBytes() const;
off_t DownloadTotalBytes() const;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
virtual void DataReceived(BUrlRequest*, const char* data,
off_t position, ssize_t size);
virtual void DownloadProgress(BUrlRequest*, ssize_t bytesReceived,
ssize_t bytesTotal);
virtual void RequestCompleted(BUrlRequest*, bool success);
#endif
protected:
virtual status_t Execute();
virtual void Cleanup(status_t jobResult);
private:
// libcurl callbacks
static int _TransferCallback(void* _job,
off_t downloadTotal, off_t downloaded,
off_t uploadTotal, off_t uploaded);
static size_t _WriteCallback(void* buffer, size_t size,
size_t nmemb, void* userp);
private:
BString fFileURL;
BEntry fTargetEntry;
BFile fTargetFile;
bool fSuccess;
float fDownloadProgress;
off_t fBytes;
off_t fTotalBytes;

View File

@ -1,30 +0,0 @@
/*
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Rene Gollent <rene@gollent.com>
*/
#ifndef HAIKU_BOOTSTRAP_BUILD
#include <curl/curl.h>
#endif
extern "C" void
initialize_after()
{
#ifndef HAIKU_BOOTSTRAP_BUILD
curl_global_init(CURL_GLOBAL_SSL);
#endif
}
extern "C" void
terminate_after()
{
#ifndef HAIKU_BOOTSTRAP_BUILD
curl_global_cleanup();
#endif
}

View File

@ -61,7 +61,6 @@ HPKG_SOURCES =
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
UseBuildFeatureHeaders curl ;
if [ FIsBuildFeatureEnabled zstd ] {
SubDirC++Flags -DZSTD_ENABLED ;
}
@ -70,11 +69,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package manager ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package solver ] ;
Includes [ FGristFiles FetchFileJob.cpp ]
: [ BuildFeatureAttribute curl : headers ] ;
Includes [ FGristFiles InitTerminateLibPackage.cpp ]
: [ BuildFeatureAttribute curl : headers ] ;
AddResources $(libsolv) :
LibsolvSolver.rdef
;
@ -92,7 +86,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
DownloadFileRequest.cpp
DropRepositoryRequest.cpp
FetchFileJob.cpp
InitTerminateLibPackage.cpp
InstallationLocationInfo.cpp
Job.cpp
PackageInfo.cpp
@ -138,7 +131,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
shared
bnetapi
be localestub
[ BuildFeatureAttribute curl : library ]
[ TargetLibstdc++ ]
$(TARGET_NETWORK_LIBS)
;

View File

@ -17,11 +17,12 @@
#include <package/ActivateRepositoryCacheJob.h>
#include <package/ChecksumAccessors.h>
#include <package/ValidateChecksumJob.h>
#include <package/FetchFileJob.h>
#include <package/RepositoryCache.h>
#include <package/RepositoryConfig.h>
#include <package/PackageRoster.h>
#include "FetchFileJob.h"
namespace BPackageKit {

View File

@ -27,10 +27,10 @@
#include <CopyEngine.h>
#include <package/ActivationTransaction.h>
#include <package/DaemonClient.h>
#include <package/FetchFileJob.h>
#include <package/manager/RepositoryBuilder.h>
#include <package/ValidateChecksumJob.h>
#include "FetchFileJob.h"
#include "PackageManagerUtils.h"
#undef B_TRANSLATION_CONTEXT