119c15fecSAndrew Lindesay /* 219c15fecSAndrew Lindesay * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3d17c92f7SAndrew Lindesay * Copyright 2016-2020, 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 1519c15fecSAndrew Lindesay #include "List.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 typedef List<BString, false> StringList; 2619c15fecSAndrew Lindesay 2719c15fecSAndrew Lindesay 28a9edb9bfSAndrew Lindesay /*! These are error codes that are sent back to the client from the server */ 29a9edb9bfSAndrew Lindesay 30a9edb9bfSAndrew Lindesay #define ERROR_CODE_NONE 0 31a9edb9bfSAndrew Lindesay #define ERROR_CODE_VALIDATION -32800 32a9edb9bfSAndrew Lindesay #define ERROR_CODE_OBJECTNOTFOUND -32801 33a9edb9bfSAndrew Lindesay #define ERROR_CODE_CAPTCHABADRESPONSE -32802 34a9edb9bfSAndrew Lindesay #define ERROR_CODE_AUTHORIZATIONFAILURE -32803 35a9edb9bfSAndrew Lindesay #define ERROR_CODE_BADPKGICON -32804 36a9edb9bfSAndrew Lindesay #define ERROR_CODE_LIMITEXCEEDED -32805 37a9edb9bfSAndrew Lindesay #define ERROR_CODE_AUTHORIZATIONRULECONFLICT -32806 38a9edb9bfSAndrew Lindesay 39018d5927SAndrew Lindesay /*! This constant can be used to indicate the lack of a rating. */ 40018d5927SAndrew Lindesay 41018d5927SAndrew Lindesay #define RATING_NONE -1 42018d5927SAndrew Lindesay 43a9edb9bfSAndrew Lindesay 4419c15fecSAndrew Lindesay class WebAppInterface { 4519c15fecSAndrew Lindesay public: 4619c15fecSAndrew Lindesay WebAppInterface(); 4719c15fecSAndrew Lindesay WebAppInterface(const WebAppInterface& other); 4819c15fecSAndrew Lindesay virtual ~WebAppInterface(); 4919c15fecSAndrew Lindesay 5019c15fecSAndrew Lindesay WebAppInterface& operator=(const WebAppInterface& other); 5119c15fecSAndrew Lindesay 52d2d4866dSAndrew Lindesay void SetAuthorization(const UserCredentials& value); 53d2d4866dSAndrew Lindesay const BString& Nickname() const; 5419c15fecSAndrew Lindesay 5580a272eeSAndrew Lindesay status_t GetChangelog( 5619c15fecSAndrew Lindesay const BString& packageName, 5719c15fecSAndrew Lindesay BMessage& message); 5819c15fecSAndrew Lindesay 59051ee9d8SAndrew Lindesay status_t RetreiveUserRatingsForPackageForDisplay( 6019c15fecSAndrew Lindesay const BString& packageName, 61051ee9d8SAndrew Lindesay const BString& webAppRepositoryCode, 6219c15fecSAndrew Lindesay int resultOffset, int maxResults, 6319c15fecSAndrew Lindesay BMessage& message); 6419c15fecSAndrew Lindesay 65051ee9d8SAndrew Lindesay status_t RetreiveUserRatingForPackageAndVersionByUser( 6619c15fecSAndrew Lindesay const BString& packageName, 6719c15fecSAndrew Lindesay const BPackageVersion& version, 6819c15fecSAndrew Lindesay const BString& architecture, 6919c15fecSAndrew Lindesay const BString& repositoryCode, 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, 7719c15fecSAndrew Lindesay const BString& repositoryCode, 7819c15fecSAndrew Lindesay const BString& languageCode, 7919c15fecSAndrew Lindesay const BString& comment, 8019c15fecSAndrew Lindesay const BString& stability, 8119c15fecSAndrew Lindesay int rating, 8219c15fecSAndrew Lindesay BMessage& message); 8319c15fecSAndrew Lindesay 8419c15fecSAndrew Lindesay status_t UpdateUserRating( 8519c15fecSAndrew Lindesay const BString& ratingID, 8619c15fecSAndrew Lindesay const BString& languageCode, 8719c15fecSAndrew Lindesay const BString& comment, 8819c15fecSAndrew Lindesay const BString& stability, 8919c15fecSAndrew Lindesay int rating, bool active, 9019c15fecSAndrew Lindesay BMessage& message); 9119c15fecSAndrew Lindesay 92d2d4866dSAndrew Lindesay status_t RetrieveUserDetailForCredentials( 93d2d4866dSAndrew Lindesay const UserCredentials& credentials, 94d17c92f7SAndrew Lindesay BMessage& message); 95d2d4866dSAndrew Lindesay 96d2d4866dSAndrew Lindesay status_t RetrieveCurrentUserDetail( 97d17c92f7SAndrew Lindesay BMessage& message); 98d2d4866dSAndrew Lindesay 9901339a54SAndrew Lindesay status_t RetrieveUserUsageConditions( 10001339a54SAndrew Lindesay const BString& code, 10101339a54SAndrew Lindesay UserUsageConditions& conditions); 10201339a54SAndrew Lindesay 103*10cd325cSAndrew Lindesay status_t AgreeUserUsageConditions(const BString& code, 104*10cd325cSAndrew Lindesay BMessage& responsePayload); 105*10cd325cSAndrew Lindesay 10619c15fecSAndrew Lindesay status_t RetrieveScreenshot( 10719c15fecSAndrew Lindesay const BString& code, 10819c15fecSAndrew Lindesay int32 width, int32 height, 10919c15fecSAndrew Lindesay BDataIO* stream); 11019c15fecSAndrew Lindesay 11119c15fecSAndrew Lindesay status_t RequestCaptcha(BMessage& message); 11219c15fecSAndrew Lindesay 11319c15fecSAndrew Lindesay status_t CreateUser(const BString& nickName, 11419c15fecSAndrew Lindesay const BString& passwordClear, 11519c15fecSAndrew Lindesay const BString& email, 11619c15fecSAndrew Lindesay const BString& captchaToken, 11719c15fecSAndrew Lindesay const BString& captchaResponse, 11819c15fecSAndrew Lindesay const BString& languageCode, 1190c82f64bSAndrew Lindesay const BString& userUsageConditionsCode, 12019c15fecSAndrew Lindesay BMessage& message); 12119c15fecSAndrew Lindesay 12219c15fecSAndrew Lindesay status_t AuthenticateUser(const BString& nickName, 12319c15fecSAndrew Lindesay const BString& passwordClear, 12419c15fecSAndrew Lindesay BMessage& message); 12519c15fecSAndrew Lindesay 126d17c92f7SAndrew Lindesay static int32 ErrorCodeFromResponse( 127d17c92f7SAndrew Lindesay BMessage& responseEnvelopeMessage); 128a9edb9bfSAndrew Lindesay 129d17c92f7SAndrew Lindesay static status_t UnpackUserDetail( 130d2d4866dSAndrew Lindesay BMessage& responseEnvelopeMessage, 131d2d4866dSAndrew Lindesay UserDetail& userDetail); 132d17c92f7SAndrew Lindesay private: 133d17c92f7SAndrew Lindesay 134d2d4866dSAndrew Lindesay 13501339a54SAndrew Lindesay status_t _RetrieveUserUsageConditionsMeta( 13601339a54SAndrew Lindesay const BString& code, BMessage& message); 13701339a54SAndrew Lindesay status_t _RetrieveUserUsageConditionsCopy( 13801339a54SAndrew Lindesay const BString& code, BDataIO* stream); 139d2d4866dSAndrew Lindesay 140a9edb9bfSAndrew Lindesay void _WriteStandardJsonRpcEnvelopeValues( 141a9edb9bfSAndrew Lindesay BJsonWriter& writer, 142a9edb9bfSAndrew Lindesay const char* methodName); 14319c15fecSAndrew Lindesay status_t _SendJsonRequest(const char* domain, 14488575af1SAndrew Lindesay const BString& jsonString, uint32 flags, 14519c15fecSAndrew Lindesay BMessage& reply) const; 146b45e8b1eSAndrew Lindesay status_t _SendJsonRequest(const char* domain, 147d2d4866dSAndrew Lindesay UserCredentials credentials, 14888575af1SAndrew Lindesay BPositionIO* requestData, 149b45e8b1eSAndrew Lindesay size_t requestDataSize, uint32 flags, 150b45e8b1eSAndrew Lindesay BMessage& reply) const; 151d2d4866dSAndrew Lindesay status_t _SendJsonRequest(const char* domain, 152d2d4866dSAndrew Lindesay BPositionIO* requestData, 153d2d4866dSAndrew Lindesay size_t requestDataSize, uint32 flags, 154d2d4866dSAndrew Lindesay BMessage& reply) const; 155d2d4866dSAndrew Lindesay 156d2d4866dSAndrew Lindesay status_t _SendRawGetRequest( 157d2d4866dSAndrew Lindesay const BString urlPathComponents, 158d2d4866dSAndrew Lindesay BDataIO* stream); 15988575af1SAndrew Lindesay static void _LogPayload(BPositionIO* requestData, 16088575af1SAndrew Lindesay size_t size); 16188575af1SAndrew Lindesay static off_t _LengthAndSeekToZero(BPositionIO* data); 16219c15fecSAndrew Lindesay 16319c15fecSAndrew Lindesay private: 164d2d4866dSAndrew Lindesay UserCredentials fCredentials; 16519c15fecSAndrew Lindesay static int fRequestIndex; 16619c15fecSAndrew Lindesay }; 16719c15fecSAndrew Lindesay 16819c15fecSAndrew Lindesay 16919c15fecSAndrew Lindesay #endif // WEB_APP_INTERFACE_H 170