NDEVR
API Documentation
NDEVRFileClient.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2020, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVRFileServer
28File: NDEVRFileClient
29Included in API: True
30Author(s): tyler.parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include "NDEVRFileServer.h"
35#include <NDEVR/NDEVRCommunicationLogic.h>
36#include <NDEVR/ServerActions.h>
37#include <NDEVR/BinaryFile.h>
38#include <NDEVR/QueueBuffer.h>
39namespace NDEVR
40{
45 {
48 HighCapacityBuffer<uint01> data;
49 };
50 class PublicPrivateKey;
54 class NDEVRSERVERCLIENT_API NDEVRFileClient : public ServerActions, public PacketListener
55 {
56 public:
57 NDEVRFileClient(NDEVRCommunicationLogic* comms);
58 ~NDEVRFileClient();
59 void setPassword(PasswordString password) { m_true_user_password = password; }
60 virtual ServerCommandReturn getUserInfo(ServerCredentials& credentials, ServerUserInfo& user_info) override;
61 virtual ServerCommandReturn updateUserInfo(ServerCredentials& old_credentials, ServerUserInfo& new_credentials) override;
62 virtual ServerCommandReturn addUser(ServerUserInfo& info, PasswordString password);
63 virtual ServerCommandReturn setUserActive(ServerCredentials& info, bool active) override;
64 virtual ServerCommandReturn checkPermission(ServerPermission& resource, bool write_permission) override;
65 virtual ServerCommandReturn deleteResource(ServerPermission& resource) override;
66 virtual ServerCommandReturn deletePermission(ServerPermission& password) override;
67 virtual ServerCommandReturn addMessages(ServerPermission& permission, Buffer<EncodedMessage>& message) override;
68 virtual ServerCommandReturn getMessages(ServerPermission& permission, Buffer<EncodedMessage>& messages, TimeSpan span) override;
69 virtual ServerCommandReturn saveToFile(ServerPermission& permission, ServerResourceInfo& Resource, const File& file);
70 virtual ServerCommandReturn getResource(ServerPermission& permission, ServerResourceInfo& Resource, bool download_preview, bool download_contents) override;
71 virtual ServerCommandReturn getResourceVersions(Buffer<ServerResourceInfo>& versions, ServerPermission& Resource, bool download_preview) override;
72 virtual ServerCommandReturn addPermission(ServerPermission& permission, ServerPermission& new_permission) override;
73 virtual ServerCommandReturn addResource(ServerPermission& permission, ServerResourceInfo& Resource) override;
74 virtual ServerCommandReturn getUsers(Buffer<ServerUserInfo>& users, ServerCredentials& credentials, bool active = true, bool inactive = false, bool awaiting_aproval = false) override;
75 virtual ServerCommandReturn getResourcePermissions(Buffer<ServerPermission>& permissions, ServerPermission& Resource) override;
76 virtual ServerCommandReturn getOwnedResources(Buffer<ServerResourceInfo>& resources, ServerCredentials& credentials, bool download_preview) override;
77 virtual ServerCommandReturn getSharedResources(Buffer<ServerResourceInfo>& resources, ServerCredentials& resource, bool download_preview) override;
78 virtual ServerCommandReturn getLibaryObjects(ServerCredentials& credentials, Buffer<ServerResourceInfo>& resources, bool download_preview) override;
79 static TranslatedString AboutOWLText();
80 static TranslatedString AboutSecureText();
81 virtual bool open(NDEVRServerInfo& info) override;
82 void close() override;
83 ServerCommandReturn downloadOWL(const StringView& url, bool download_preview, bool download_contents, InfoPipe* log);
84 ServerCommandReturn downloadOWL(const Buffer<uint01>& data, bool download_preview, bool download_contents, InfoPipe* log);
85 bool connectWithOWL(const StringView& url);
86 String OWLURL() const;
87 String OWLURL(ServerPermission permission) const;
88 Buffer<uint01> OWLData(const ServerPermission& permission, UUID decrypt_password) const;
89 void onReceive(NDEVRConnectionData& data) override;
90 const ServerResourceInfo& resourceInfo() const { return m_resource_info; }
91 const ServerUserInfo& userInfo() const { return m_user_info; }
92 const ServerCommandReturn& returnCode() const { return m_return_code; }
93 const ServerPermission& permission() const { return m_permission; }
94 ServerPermission& permission() { return m_permission; }
95 const Buffer<ServerResourceInfo>& resources() const { return m_resources; }
96 const Buffer<ServerPermission> permissions() const { return m_permissions; }
97 File writePayloadToFile();
98 File saveAsFile() const;
99 void clearSaveFile();
100 void writePayloadToFile(File file);
101 void compressFile(File file, File compressed_output, const Vector<32, uint01>& password);
102 File writeOWLToFile();
103 void writeOWLToFile(File file);
104 UUID getDecryptPassword(const ServerPermission& resource) const;
105 UUID getLinkPassword(const ServerPermission& resource) const;
106 Vector<32, uint01> getEncodingPassword(const ServerPermission& resource);
107 void setDecryptPassword(UUID decrypt_password) { m_decrypt_password = decrypt_password; }
108 virtual ServerCommandReturn addOrUpdateLibaryObject(ServerPermission& credentials, UUID id, ServerResourceInfo& resource) override;
109 virtual ServerCommandReturn getLibaryObject(ServerCredentials& credentials, UUID id, ServerResourceInfo& resource, bool download_preview, bool download_contents) override;
110 void fillOutCredentials(ServerCredentials& credentials, ServerCredentials& target);
111 virtual ServerCommandReturn pushData();
112 HighCapacityBuffer<uint01> makeCurrentPacket() const;
113 protected:
114 virtual ServerCommandReturn addUser(ServerUserInfo& info) override;
115 void waitUntilFinished(uint04 id, InfoPipe* log);
116 bool isJobFinished(uint04 id) const;
117 void sendPacket();
118 Vector<32, uint01> aesKey() const;
119 protected:
120 File m_save_file;
121 PublicPrivateKey* m_key = nullptr;
122 sint04 m_user_id = Constant<sint04>::Invalid;
123 QueueBuffer<PendingAction> m_pending_actions;
124 Buffer<ServerResourceInfo> m_resources;
125 Buffer<EncodedMessage> m_encoded_messages;
126 Buffer<ServerPermission> m_permissions;
127 uint04 m_command_number = 0;
128 void* m_main_server_socket = nullptr;
129 ServerRequestType m_request_mode_to_push;
130 ServerRequestType m_active_request_mode = ServerRequestType::e_get_server_info;
131 ServerResourceInfo m_resource_info;
132 ServerUserInfo m_user_info;
133 ServerUserInfo m_new_user_info;
134 ServerPermission m_permission;
135 PasswordString m_true_user_password;
136 UUID m_library_object;
137 UUID m_decrypt_password;
138 ServerPermission m_new_permission;
139 NDEVRCommunicationLogic* m_comms = nullptr;
140 TimeSpan m_timespan = Constant<TimeSpan>::Invalid;
141 ServerCommandReturn m_return_code = ServerCommandReturn::e_success;
142 bool m_download_preview = false;
143 bool m_download_contents = false;
144 bool m_only_active = false;
145 bool m_is_blocking = true;
146 bool m_write_permission = false;
147 };
148}
Interface for objects that wish to receive NDEVR packet events and connection state changes.
When passwords are used inside the NDEVR engine, we don't want them logged or visible.
Manages an elliptic curve public/private key pair for asymmetric encryption and decryption.
Abstract interface for all server-side CRUD operations on users, resources, and permissions.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
ServerRequestType
Enumerates the types of requests that can be sent between NDEVR file clients and servers.
Represents a server request that has been sent and is awaiting a response.
HighCapacityBuffer< uint01 > data
Response data payload once received.
ServerRequestType request_mode
The type of request that was sent.
uint04 id
Unique command ID for matching responses.