NDEVR
API Documentation
DirectServerAction.h
1#pragma once
2#include <NDEVR/ServerActions.h>
3#include "DLLInfo.h"
4#include <NDEVR/String.h>
5#include <NDEVR/PasswordString.h>
6#include <NDEVR/DynamicPointer.h>
7#include <NDEVR/NDEVRFileServer.h>
8#include <NDEVR/ApplicationOption.h>
9namespace sql
10{
11 class Connection;
12 class PreparedStatement;
13 class ResultSet;
14 namespace mysql
15 {
16 class MySQL_Driver;
17 }
18}
19namespace NDEVR
20{
24 class DirectServerAction : public ServerActions
25 {
26 public:
27 DirectServerAction(LogPtr log);
28 bool open(NDEVRServerInfo& info) override;
29 void close() override;
30 void setResourceDirectory(const File& file);
31 virtual ServerCommandReturn updateUserInfo(ServerCredentials& old_credentials, ServerUserInfo& new_credentials) override;
32 virtual ServerCommandReturn addUser(ServerUserInfo& info) override;
33 virtual ServerCommandReturn getUserInfo(ServerCredentials& credentials, ServerUserInfo& user_info) override;
34 virtual ServerCommandReturn checkCredentials(ServerCredentials& credentials);
35 virtual ServerCommandReturn setUserActive(ServerCredentials& info, bool active) override;
36 virtual ServerCommandReturn checkPermission(ServerPermission& resource, bool write_permission) override;
37 virtual ServerCommandReturn deleteResource(ServerPermission& resource) override;
38 virtual ServerCommandReturn addMessages(ServerPermission& permission, Buffer<EncodedMessage>& message) override;
39 virtual ServerCommandReturn getMessages(ServerPermission& permission, Buffer<EncodedMessage>& messages, TimeSpan span) override;
40 virtual ServerCommandReturn deletePermission(ServerPermission& password) override;
41 virtual ServerCommandReturn getLibaryObjects(ServerCredentials& credentials, Buffer<ServerResourceInfo>& resources, bool download_preview) override;
42 virtual ServerCommandReturn getResource(ServerPermission& permission, ServerResourceInfo& Resource, bool download_preview, bool download_contents) override;
43 virtual ServerCommandReturn getResourceVersions(Buffer<ServerResourceInfo>& versions, ServerPermission& permission, bool download_preview) override;
44 virtual ServerCommandReturn addPermission(ServerPermission& our_permission, ServerPermission& new_permission) override;
45 virtual ServerCommandReturn addResource(ServerPermission& permission, ServerResourceInfo& Resource) override;
46 virtual ServerCommandReturn getUsers(Buffer<ServerUserInfo>& users, ServerCredentials& credentials, bool active = true, bool inactive = false, bool awaiting_aproval = false) override;
47 virtual ServerCommandReturn getResourcePermissions(Buffer<ServerPermission>& permissions, ServerPermission& Resource) override;
48 virtual ServerCommandReturn getOwnedResources(Buffer<ServerResourceInfo>& resources, ServerCredentials& credentials, bool download_preview) override;
49 virtual ServerCommandReturn getSharedResources(Buffer<ServerResourceInfo>& resources, ServerCredentials& resource, bool download_preview) override;
50 virtual ServerCommandReturn forceUserActive(ServerCredentials& info, bool active) override;
51 sint04 resolveUserID(const StringView& username, bool active = true);
52 sint04 resolveUserViaPhoneNumber(const StringView& phone_number, bool active = true);
53 sint04 resolveUserViaEmail(const StringView& email, bool active = true);
54 sint04 resolveResourceID(const StringView& resource_name, sint04 owner_id);
55 sint04 resolvePermissionID(const StringView& resource_name, sint04 owner_id);
56 sint04 resourceOwnerUserID(sint04 resource_id);
57 bool resolveUserIDIfNeeded(ServerCredentials& permission, bool active = true);
58 bool resolveResourceIDIfNeeded(ResourceID& permission, sint04 user_id);
59 bool resolvePermissionIDIfNeeded(ServerPermission& permission);
60 bool isRateLimited(const ServerCredentials& ip);
61 virtual ServerCommandReturn addOrUpdateLibaryObject(ServerPermission& credentials, UUID id, ServerResourceInfo& resource) override;
62 virtual ServerCommandReturn getLibaryObject(ServerCredentials& credentials, UUID id, ServerResourceInfo& resource, bool download_preview, bool download_contents) override;
63 virtual bool needsReconnect() const;
64 virtual bool reconnect() const;
65 void logAction(const ServerCredentials& ip, const ServerCommandReturn& return_val, uint04 request_type) override;
66 private:
67 sql::PreparedStatement* statement(const StringView& statement) const;
68 virtual ServerCommandReturn hasUserOrEmail(ServerUserInfo& info, bool active_user);
69 virtual ServerCommandReturn getResourceAfterPermissionCheck(ServerResourceInfo& file, bool download_preview, bool download_contents, InfoPipe* log = nullptr);
70 ServerCommandReturn updateUserInfoAfterPermissionCheck(ServerUserInfo& info);
71 ServerCommandReturn addOrUpdateSharedLinkPermission(ServerPermission& permission, EncodedMessage& message);
72 ServerCommandReturn getSharedLinkPermissions(ServerCredentials& permission, Buffer<ServerPermission>& out);
73 ServerCommandReturn getPublicPermissions(ServerCredentials& permission, Buffer<ServerPermission>& out);
74 ServerCommandReturn getPermissionInfo(ServerPermission& permission);
75 void updateAccessTime(ServerCredentials& credentials, ServerResourceInfo& file, bool is_write);
76 void getPermissionInfo(const DynamicPointer<sql::ResultSet>& res, ServerPermission& permission);
77 bool getSharedPermissionPassword(const DynamicPointer<sql::ResultSet>& res, ServerPermission& permission);
78 void getPublicPermissionInfo(ServerPermission& permission);
79 sql::mysql::MySQL_Driver* m_driver;
80 sql::Connection* m_connection;
81 File m_resource_location;
82 LogPtr m_log;
83 public:
92 };
93}
The default object to store data of any type that should persist through sessions of the application.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Dictionary< uint08, sql::PreparedStatement * > m_cached_statements
Cache of prepared SQL statements.
static ApplicationOption< String > username
Database login username.
static ApplicationOption< uint04 > max_login_failure_count
Max failed logins before lockout.
static ApplicationOption< sint04 > login_check_interval_minutes
Interval in minutes for rate limiting checks.
static ApplicationOption< uint04 > port
Database server port.
Dictionary< sint04, sint04 > resource_ownership_lookup
Cache of resource ID to owner ID mappings.
static ApplicationOption< String > address
Database server address.
static ApplicationOption< PasswordString > password
Database login password.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A light-weight base class for Log that allows processes to update, without the need for additional in...
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
Abstract interface for all server-side CRUD operations on users, resources, and permissions.
The core String View class for the NDEVR API.
Definition StringView.h:58
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
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.
@ file
The source file path associated with this object.
Represents an encoded message associated with a resource version, including header and body.
Contains the address, credentials, and security flag needed to connect to an NDEVR server.
Identifies a resource on the server by name, ID, owner, and version.
Encapsulates a server command's return status, including a code and optional message.
Stores user credentials for server authentication, including username, password hash,...
Defines permissions for a user to access a specific resource, including encryption data.
Metadata for a server-hosted resource including type, timestamps, size, and cached data.
Extended user information including contact details and encryption keys.