119c15fecSAndrew Lindesay /* 219c15fecSAndrew Lindesay * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3*133ebab6SAndrew Lindesay * Copyright 2016-2021, Andrew Lindesay <apl@lindesay.co.nz>. 419c15fecSAndrew Lindesay * All rights reserved. Distributed under the terms of the MIT License. 519c15fecSAndrew Lindesay */ 619c15fecSAndrew Lindesay #ifndef WEB_APP_INTERFACE_H 719c15fecSAndrew Lindesay #define WEB_APP_INTERFACE_H 819c15fecSAndrew Lindesay 919c15fecSAndrew Lindesay 1019c15fecSAndrew Lindesay #include <Application.h> 11a9edb9bfSAndrew Lindesay #include <JsonWriter.h> 1219c15fecSAndrew Lindesay #include <String.h> 1319c15fecSAndrew Lindesay #include <package/PackageVersion.h> 1419c15fecSAndrew Lindesay 15*133ebab6SAndrew Lindesay #include "PackageInfo.h" 16d2d4866dSAndrew Lindesay #include "UserCredentials.h" 17d2d4866dSAndrew Lindesay #include "UserDetail.h" 1801339a54SAndrew Lindesay #include "UserUsageConditions.h" 1919c15fecSAndrew Lindesay 2019c15fecSAndrew Lindesay 2119c15fecSAndrew Lindesay class BDataIO; 2219c15fecSAndrew Lindesay class BMessage; 2319c15fecSAndrew Lindesay using BPackageKit::BPackageVersion; 2419c15fecSAndrew Lindesay 2519c15fecSAndrew Lindesay 26a9edb9bfSAndrew Lindesay /*! These are error codes that are sent back to the client from the server */ 27a9edb9bfSAndrew Lindesay 28a9edb9bfSAndrew Lindesay #define ERROR_CODE_NONE 0 29a9edb9bfSAndrew Lindesay #define ERROR_CODE_VALIDATION -32800 30a9edb9bfSAndrew Lindesay #define ERROR_CODE_OBJECTNOTFOUND -32801 31a9edb9bfSAndrew Lindesay #define ERROR_CODE_CAPTCHABADRESPONSE -32802 32a9edb9bfSAndrew Lindesay #define ERROR_CODE_AUTHORIZATIONFAILURE -32803 33a9edb9bfSAndrew Lindesay #define ERROR_CODE_BADPKGICON -32804 34a9edb9bfSAndrew Lindesay #define ERROR_CODE_LIMITEXCEEDED -32805 35a9edb9bfSAndrew Lindesay #define ERROR_CODE_AUTHORIZATIONRULECONFLICT -32806 36a9edb9bfSAndrew Lindesay 37018d5927SAndrew Lindesay /*! This constant can be used to indicate the lack of a rating. */ 38018d5927SAndrew Lindesay 39018d5927SAndrew Lindesay #define RATING_NONE -1 40018d5927SAndrew Lindesay 41a9edb9bfSAndrew Lindesay 4219c15fecSAndrew Lindesay class WebAppInterface { 4319c15fecSAndrew Lindesay public: 4419c15fecSAndrew Lindesay WebAppInterface(); 4519c15fecSAndrew Lindesay WebAppInterface(const WebAppInterface& other); 4619c15fecSAndrew Lindesay virtual ~WebAppInterface(); 4719c15fecSAndrew Lindesay 4819c15fecSAndrew Lindesay WebAppInterface& operator=(const WebAppInterface& other); 4919c15fecSAndrew Lindesay 50d2d4866dSAndrew Lindesay void SetAuthorization(const UserCredentials& value); 51d2d4866dSAndrew Lindesay const BString& Nickname() const; 5219c15fecSAndrew Lindesay 5380a272eeSAndrew Lindesay status_t GetChangelog( 5419c15fecSAndrew Lindesay const BString& packageName, 5519c15fecSAndrew Lindesay BMessage& message); 5619c15fecSAndrew Lindesay 57051ee9d8SAndrew Lindesay status_t RetreiveUserRatingsForPackageForDisplay( 5819c15fecSAndrew Lindesay const BString& packageName, 59051ee9d8SAndrew Lindesay const BString& webAppRepositoryCode, 6019c15fecSAndrew Lindesay int resultOffset, int maxResults, 6119c15fecSAndrew Lindesay BMessage& message); 6219c15fecSAndrew Lindesay 63051ee9d8SAndrew Lindesay status_t RetreiveUserRatingForPackageAndVersionByUser( 6419c15fecSAndrew Lindesay const BString& packageName, 6519c15fecSAndrew Lindesay const BPackageVersion& version, 6619c15fecSAndrew Lindesay const BString& architecture, 6719c15fecSAndrew Lindesay const BString& repositoryCode, 68d2d4866dSAndrew Lindesay const BString& userNickname, 6919c15fecSAndrew Lindesay BMessage& message); 7019c15fecSAndrew Lindesay 7119c15fecSAndrew Lindesay status_t CreateUserRating( 7219c15fecSAndrew Lindesay const BString& packageName, 73a9edb9bfSAndrew Lindesay const BPackageVersion& version, 7419c15fecSAndrew Lindesay const BString& architecture, 7519c15fecSAndrew Lindesay const BString& repositoryCode, 7619c15fecSAndrew Lindesay const BString& languageCode, 7719c15fecSAndrew Lindesay const BString& comment, 7819c15fecSAndrew Lindesay const BString& stability, 7919c15fecSAndrew Lindesay int rating, 8019c15fecSAndrew Lindesay BMessage& message); 8119c15fecSAndrew Lindesay 8219c15fecSAndrew Lindesay status_t UpdateUserRating( 8319c15fecSAndrew Lindesay const BString& ratingID, 8419c15fecSAndrew Lindesay const BString& languageCode, 8519c15fecSAndrew Lindesay const BString& comment, 8619c15fecSAndrew Lindesay const BString& stability, 8719c15fecSAndrew Lindesay int rating, bool active, 8819c15fecSAndrew Lindesay BMessage& message); 8919c15fecSAndrew Lindesay 90d2d4866dSAndrew Lindesay status_t RetrieveUserDetailForCredentials( 91d2d4866dSAndrew Lindesay const UserCredentials& credentials, 92d17c92f7SAndrew Lindesay BMessage& message); 93d2d4866dSAndrew Lindesay 94d2d4866dSAndrew Lindesay status_t RetrieveCurrentUserDetail( 95d17c92f7SAndrew Lindesay BMessage& message); 96d2d4866dSAndrew Lindesay 9701339a54SAndrew Lindesay status_t RetrieveUserUsageConditions( 9801339a54SAndrew Lindesay const BString& code, 9901339a54SAndrew Lindesay UserUsageConditions& conditions); 10001339a54SAndrew Lindesay 10110cd325cSAndrew Lindesay status_t AgreeUserUsageConditions(const BString& code, 10210cd325cSAndrew Lindesay BMessage& responsePayload); 10310cd325cSAndrew Lindesay 10419c15fecSAndrew Lindesay status_t RetrieveScreenshot( 10519c15fecSAndrew Lindesay const BString& code, 10619c15fecSAndrew Lindesay int32 width, int32 height, 10719c15fecSAndrew Lindesay BDataIO* stream); 10819c15fecSAndrew Lindesay 10919c15fecSAndrew Lindesay status_t RequestCaptcha(BMessage& message); 11019c15fecSAndrew Lindesay 11119c15fecSAndrew Lindesay status_t CreateUser(const BString& nickName, 11219c15fecSAndrew Lindesay const BString& passwordClear, 11319c15fecSAndrew Lindesay const BString& email, 11419c15fecSAndrew Lindesay const BString& captchaToken, 11519c15fecSAndrew Lindesay const BString& captchaResponse, 11619c15fecSAndrew Lindesay const BString& languageCode, 1170c82f64bSAndrew Lindesay const BString& userUsageConditionsCode, 11819c15fecSAndrew Lindesay BMessage& message); 11919c15fecSAndrew Lindesay 12019c15fecSAndrew Lindesay status_t AuthenticateUser(const BString& nickName, 12119c15fecSAndrew Lindesay const BString& passwordClear, 12219c15fecSAndrew Lindesay BMessage& message); 12319c15fecSAndrew Lindesay 124*133ebab6SAndrew Lindesay status_t IncrementViewCounter( 125*133ebab6SAndrew Lindesay const PackageInfoRef package, 126*133ebab6SAndrew Lindesay const DepotInfoRef depot, 127*133ebab6SAndrew Lindesay BMessage& message); 128*133ebab6SAndrew Lindesay 129d17c92f7SAndrew Lindesay static int32 ErrorCodeFromResponse( 130d17c92f7SAndrew Lindesay BMessage& responseEnvelopeMessage); 131a9edb9bfSAndrew Lindesay 132d17c92f7SAndrew Lindesay static status_t UnpackUserDetail( 133d2d4866dSAndrew Lindesay BMessage& responseEnvelopeMessage, 134d2d4866dSAndrew Lindesay UserDetail& userDetail); 135d17c92f7SAndrew Lindesay private: 136d17c92f7SAndrew Lindesay 137d2d4866dSAndrew Lindesay 13801339a54SAndrew Lindesay status_t _RetrieveUserUsageConditionsMeta( 13901339a54SAndrew Lindesay const BString& code, BMessage& message); 14001339a54SAndrew Lindesay status_t _RetrieveUserUsageConditionsCopy( 14101339a54SAndrew Lindesay const BString& code, BDataIO* stream); 142d2d4866dSAndrew Lindesay 143a9edb9bfSAndrew Lindesay void _WriteStandardJsonRpcEnvelopeValues( 144a9edb9bfSAndrew Lindesay BJsonWriter& writer, 145a9edb9bfSAndrew Lindesay const char* methodName); 14619c15fecSAndrew Lindesay status_t _SendJsonRequest(const char* domain, 14788575af1SAndrew Lindesay const BString& jsonString, uint32 flags, 14819c15fecSAndrew Lindesay BMessage& reply) const; 149b45e8b1eSAndrew Lindesay status_t _SendJsonRequest(const char* domain, 150d2d4866dSAndrew Lindesay UserCredentials credentials, 15188575af1SAndrew Lindesay BPositionIO* requestData, 152b45e8b1eSAndrew Lindesay size_t requestDataSize, uint32 flags, 153b45e8b1eSAndrew Lindesay BMessage& reply) const; 154d2d4866dSAndrew Lindesay status_t _SendJsonRequest(const char* domain, 155d2d4866dSAndrew Lindesay BPositionIO* requestData, 156d2d4866dSAndrew Lindesay size_t requestDataSize, uint32 flags, 157d2d4866dSAndrew Lindesay BMessage& reply) const; 158d2d4866dSAndrew Lindesay 159d2d4866dSAndrew Lindesay status_t _SendRawGetRequest( 160d2d4866dSAndrew Lindesay const BString urlPathComponents, 161d2d4866dSAndrew Lindesay BDataIO* stream); 16288575af1SAndrew Lindesay static void _LogPayload(BPositionIO* requestData, 16388575af1SAndrew Lindesay size_t size); 16488575af1SAndrew Lindesay static off_t _LengthAndSeekToZero(BPositionIO* data); 16519c15fecSAndrew Lindesay 16619c15fecSAndrew Lindesay private: 167d2d4866dSAndrew Lindesay UserCredentials fCredentials; 16819c15fecSAndrew Lindesay static int fRequestIndex; 16919c15fecSAndrew Lindesay }; 17019c15fecSAndrew Lindesay 17119c15fecSAndrew Lindesay 17219c15fecSAndrew Lindesay #endif // WEB_APP_INTERFACE_H 173