1 /* 2 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2016-2020, Andrew Lindesay <apl@lindesay.co.nz>. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 #ifndef WEB_APP_INTERFACE_H 7 #define WEB_APP_INTERFACE_H 8 9 10 #include <Application.h> 11 #include <JsonWriter.h> 12 #include <String.h> 13 #include <package/PackageVersion.h> 14 15 #include "List.h" 16 #include "UserCredentials.h" 17 #include "UserDetail.h" 18 #include "UserUsageConditions.h" 19 20 21 class BDataIO; 22 class BMessage; 23 using BPackageKit::BPackageVersion; 24 25 typedef List<BString, false> StringList; 26 27 28 /*! These are error codes that are sent back to the client from the server */ 29 30 #define ERROR_CODE_NONE 0 31 #define ERROR_CODE_VALIDATION -32800 32 #define ERROR_CODE_OBJECTNOTFOUND -32801 33 #define ERROR_CODE_CAPTCHABADRESPONSE -32802 34 #define ERROR_CODE_AUTHORIZATIONFAILURE -32803 35 #define ERROR_CODE_BADPKGICON -32804 36 #define ERROR_CODE_LIMITEXCEEDED -32805 37 #define ERROR_CODE_AUTHORIZATIONRULECONFLICT -32806 38 39 /*! This constant can be used to indicate the lack of a rating. */ 40 41 #define RATING_NONE -1 42 43 44 class WebAppInterface { 45 public: 46 WebAppInterface(); 47 WebAppInterface(const WebAppInterface& other); 48 virtual ~WebAppInterface(); 49 50 WebAppInterface& operator=(const WebAppInterface& other); 51 52 void SetAuthorization(const UserCredentials& value); 53 const BString& Nickname() const; 54 55 status_t GetChangelog( 56 const BString& packageName, 57 BMessage& message); 58 59 status_t RetreiveUserRatingsForPackageForDisplay( 60 const BString& packageName, 61 const BString& webAppRepositoryCode, 62 int resultOffset, int maxResults, 63 BMessage& message); 64 65 status_t RetreiveUserRatingForPackageAndVersionByUser( 66 const BString& packageName, 67 const BPackageVersion& version, 68 const BString& architecture, 69 const BString& repositoryCode, 70 const BString& userNickname, 71 BMessage& message); 72 73 status_t CreateUserRating( 74 const BString& packageName, 75 const BPackageVersion& version, 76 const BString& architecture, 77 const BString& repositoryCode, 78 const BString& languageCode, 79 const BString& comment, 80 const BString& stability, 81 int rating, 82 BMessage& message); 83 84 status_t UpdateUserRating( 85 const BString& ratingID, 86 const BString& languageCode, 87 const BString& comment, 88 const BString& stability, 89 int rating, bool active, 90 BMessage& message); 91 92 status_t RetrieveUserDetailForCredentials( 93 const UserCredentials& credentials, 94 BMessage& message); 95 96 status_t RetrieveCurrentUserDetail( 97 BMessage& message); 98 99 status_t RetrieveUserUsageConditions( 100 const BString& code, 101 UserUsageConditions& conditions); 102 103 status_t AgreeUserUsageConditions(const BString& code, 104 BMessage& responsePayload); 105 106 status_t RetrieveScreenshot( 107 const BString& code, 108 int32 width, int32 height, 109 BDataIO* stream); 110 111 status_t RequestCaptcha(BMessage& message); 112 113 status_t CreateUser(const BString& nickName, 114 const BString& passwordClear, 115 const BString& email, 116 const BString& captchaToken, 117 const BString& captchaResponse, 118 const BString& languageCode, 119 const BString& userUsageConditionsCode, 120 BMessage& message); 121 122 status_t AuthenticateUser(const BString& nickName, 123 const BString& passwordClear, 124 BMessage& message); 125 126 static int32 ErrorCodeFromResponse( 127 BMessage& responseEnvelopeMessage); 128 129 static status_t UnpackUserDetail( 130 BMessage& responseEnvelopeMessage, 131 UserDetail& userDetail); 132 private: 133 134 135 status_t _RetrieveUserUsageConditionsMeta( 136 const BString& code, BMessage& message); 137 status_t _RetrieveUserUsageConditionsCopy( 138 const BString& code, BDataIO* stream); 139 140 void _WriteStandardJsonRpcEnvelopeValues( 141 BJsonWriter& writer, 142 const char* methodName); 143 status_t _SendJsonRequest(const char* domain, 144 const BString& jsonString, uint32 flags, 145 BMessage& reply) const; 146 status_t _SendJsonRequest(const char* domain, 147 UserCredentials credentials, 148 BPositionIO* requestData, 149 size_t requestDataSize, uint32 flags, 150 BMessage& reply) const; 151 status_t _SendJsonRequest(const char* domain, 152 BPositionIO* requestData, 153 size_t requestDataSize, uint32 flags, 154 BMessage& reply) const; 155 156 status_t _SendRawGetRequest( 157 const BString urlPathComponents, 158 BDataIO* stream); 159 static void _LogPayload(BPositionIO* requestData, 160 size_t size); 161 static off_t _LengthAndSeekToZero(BPositionIO* data); 162 163 private: 164 UserCredentials fCredentials; 165 static int fRequestIndex; 166 }; 167 168 169 #endif // WEB_APP_INTERFACE_H 170