119c15fecSAndrew Lindesay /* 219c15fecSAndrew Lindesay * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3*f6e22563SAndrew Lindesay * Copyright 2016-2022, 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 15133ebab6SAndrew 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, 60*f6e22563SAndrew Lindesay const BString& webAppRepositorySourceCode, 6119c15fecSAndrew Lindesay int resultOffset, int maxResults, 6219c15fecSAndrew Lindesay BMessage& message); 6319c15fecSAndrew Lindesay 64051ee9d8SAndrew Lindesay status_t RetreiveUserRatingForPackageAndVersionByUser( 6519c15fecSAndrew Lindesay const BString& packageName, 6619c15fecSAndrew Lindesay const BPackageVersion& version, 6719c15fecSAndrew Lindesay const BString& architecture, 68*f6e22563SAndrew Lindesay const BString& webAppRepositoryCode, 69*f6e22563SAndrew Lindesay const BString& webAppRepositorySourceCode, 70d2d4866dSAndrew Lindesay const BString& userNickname, 7119c15fecSAndrew Lindesay BMessage& message); 7219c15fecSAndrew Lindesay 7319c15fecSAndrew Lindesay status_t CreateUserRating( 7419c15fecSAndrew Lindesay const BString& packageName, 75a9edb9bfSAndrew Lindesay const BPackageVersion& version, 7619c15fecSAndrew Lindesay const BString& architecture, 77*f6e22563SAndrew Lindesay const BString& webAppRepositoryCode, 78*f6e22563SAndrew Lindesay const BString& webAppRepositorySourceCode, 7919c15fecSAndrew Lindesay const BString& languageCode, 8019c15fecSAndrew Lindesay const BString& comment, 8119c15fecSAndrew Lindesay const BString& stability, 8219c15fecSAndrew Lindesay int rating, 8319c15fecSAndrew Lindesay BMessage& message); 8419c15fecSAndrew Lindesay 8519c15fecSAndrew Lindesay status_t UpdateUserRating( 8619c15fecSAndrew Lindesay const BString& ratingID, 8719c15fecSAndrew Lindesay const BString& languageCode, 8819c15fecSAndrew Lindesay const BString& comment, 8919c15fecSAndrew Lindesay const BString& stability, 9019c15fecSAndrew Lindesay int rating, bool active, 9119c15fecSAndrew Lindesay BMessage& message); 9219c15fecSAndrew Lindesay 93d2d4866dSAndrew Lindesay status_t RetrieveUserDetailForCredentials( 94d2d4866dSAndrew Lindesay const UserCredentials& credentials, 95d17c92f7SAndrew Lindesay BMessage& message); 96d2d4866dSAndrew Lindesay 97d2d4866dSAndrew Lindesay status_t RetrieveCurrentUserDetail( 98d17c92f7SAndrew Lindesay BMessage& message); 99d2d4866dSAndrew Lindesay 10001339a54SAndrew Lindesay status_t RetrieveUserUsageConditions( 10101339a54SAndrew Lindesay const BString& code, 10201339a54SAndrew Lindesay UserUsageConditions& conditions); 10301339a54SAndrew Lindesay 10410cd325cSAndrew Lindesay status_t AgreeUserUsageConditions(const BString& code, 10510cd325cSAndrew Lindesay BMessage& responsePayload); 10610cd325cSAndrew Lindesay 10719c15fecSAndrew Lindesay status_t RetrieveScreenshot( 10819c15fecSAndrew Lindesay const BString& code, 10919c15fecSAndrew Lindesay int32 width, int32 height, 11019c15fecSAndrew Lindesay BDataIO* stream); 11119c15fecSAndrew Lindesay 11219c15fecSAndrew Lindesay status_t RequestCaptcha(BMessage& message); 11319c15fecSAndrew Lindesay 11419c15fecSAndrew Lindesay status_t CreateUser(const BString& nickName, 11519c15fecSAndrew Lindesay const BString& passwordClear, 11619c15fecSAndrew Lindesay const BString& email, 11719c15fecSAndrew Lindesay const BString& captchaToken, 11819c15fecSAndrew Lindesay const BString& captchaResponse, 11919c15fecSAndrew Lindesay const BString& languageCode, 1200c82f64bSAndrew Lindesay const BString& userUsageConditionsCode, 12119c15fecSAndrew Lindesay BMessage& message); 12219c15fecSAndrew Lindesay 12319c15fecSAndrew Lindesay status_t AuthenticateUser(const BString& nickName, 12419c15fecSAndrew Lindesay const BString& passwordClear, 12519c15fecSAndrew Lindesay BMessage& message); 12619c15fecSAndrew Lindesay 127133ebab6SAndrew Lindesay status_t IncrementViewCounter( 128133ebab6SAndrew Lindesay const PackageInfoRef package, 129133ebab6SAndrew Lindesay const DepotInfoRef depot, 130133ebab6SAndrew Lindesay BMessage& message); 131133ebab6SAndrew Lindesay 132d17c92f7SAndrew Lindesay static int32 ErrorCodeFromResponse( 133d17c92f7SAndrew Lindesay BMessage& responseEnvelopeMessage); 134a9edb9bfSAndrew Lindesay 135d17c92f7SAndrew Lindesay static status_t UnpackUserDetail( 136d2d4866dSAndrew Lindesay BMessage& responseEnvelopeMessage, 137d2d4866dSAndrew Lindesay UserDetail& userDetail); 138d17c92f7SAndrew Lindesay private: 139d17c92f7SAndrew Lindesay 140d2d4866dSAndrew Lindesay 14101339a54SAndrew Lindesay status_t _RetrieveUserUsageConditionsMeta( 14201339a54SAndrew Lindesay const BString& code, BMessage& message); 14301339a54SAndrew Lindesay status_t _RetrieveUserUsageConditionsCopy( 14401339a54SAndrew Lindesay const BString& code, BDataIO* stream); 145d2d4866dSAndrew Lindesay 14621df7324SAndrew Lindesay status_t _SendJsonRequest(const char* urlPathComponents, 14788575af1SAndrew Lindesay const BString& jsonString, uint32 flags, 14819c15fecSAndrew Lindesay BMessage& reply) const; 14921df7324SAndrew Lindesay status_t _SendJsonRequest(const char* urlPathComponents, 150d2d4866dSAndrew Lindesay UserCredentials credentials, 15188575af1SAndrew Lindesay BPositionIO* requestData, 152b45e8b1eSAndrew Lindesay size_t requestDataSize, uint32 flags, 153b45e8b1eSAndrew Lindesay BMessage& reply) const; 15421df7324SAndrew Lindesay status_t _SendJsonRequest(const char* urlPathComponents, 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