1 /* 2 * Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #ifndef ABSTRACT_SERVER_PROCESS_H 8 #define ABSTRACT_SERVER_PROCESS_H 9 10 #include <HttpRequest.h> 11 #include <Json.h> 12 #include <String.h> 13 #include <Url.h> 14 15 #include "AbstractProcess.h" 16 #include "StandardMetaData.h" 17 18 19 typedef enum server_process_options { 20 SERVER_PROCESS_NO_NETWORKING = 1 << 0, 21 SERVER_PROCESS_PREFER_CACHE = 1 << 1, 22 SERVER_PROCESS_DROP_CACHE = 1 << 2 23 } server_process_options; 24 25 26 /*! This is the superclass of Processes that communicate with the Haiku Depot 27 Server (HDS) system. 28 */ 29 30 31 class AbstractServerProcess : public AbstractProcess { 32 public: 33 AbstractServerProcess(uint32 options); 34 virtual ~AbstractServerProcess(); 35 36 protected: 37 virtual status_t GetStandardMetaDataPath( 38 BPath& path) const = 0; 39 virtual void GetStandardMetaDataJsonPath( 40 BString& jsonPath) const = 0; 41 42 status_t IfModifiedSinceHeaderValue( 43 BString& headerValue) const; 44 status_t IfModifiedSinceHeaderValue( 45 BString& headerValue, 46 const BPath& metaDataPath, 47 const BString& jsonPath) const; 48 49 status_t PopulateMetaData( 50 StandardMetaData& metaData, 51 const BPath& path, 52 const BString& jsonPath) const; 53 54 status_t ParseJsonFromFileWithListener( 55 BJsonEventListener *listener, 56 const BPath& path) const; 57 58 status_t DownloadToLocalFileAtomically( 59 const BPath& targetFilePath, 60 const BUrl& url); 61 62 status_t DeleteLocalFile(const BPath& filePath); 63 status_t MoveDamagedFileAside(const BPath& filePath); 64 65 bool HasOption(uint32 flag); 66 bool ShouldAttemptNetworkDownload( 67 bool hasDataAlready); 68 69 static bool IsSuccess(status_t e); 70 71 protected: 72 virtual status_t StopInternal(); 73 74 private: 75 uint32 fOptions; 76 77 BHttpRequest* fRequest; 78 79 status_t DownloadToLocalFile( 80 const BPath& targetFilePath, 81 const BUrl& url, 82 uint32 redirects, uint32 failures); 83 84 static bool LooksLikeGzip(const char *pathStr); 85 86 }; 87 88 #endif // ABSTRACT_SERVER_PROCESS_H 89