1
1
/*
2
- * Copyright 2018-2024 ObjectBox Ltd. All rights reserved.
2
+ * Copyright 2018-2025 ObjectBox Ltd. All rights reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
34
34
#include "objectbox.h"
35
35
36
36
#if defined(static_assert ) || defined(__cplusplus )
37
- static_assert (OBX_VERSION_MAJOR == 4 && OBX_VERSION_MINOR == 0 && OBX_VERSION_PATCH == 2 , // NOLINT
37
+ static_assert (OBX_VERSION_MAJOR == 4 && OBX_VERSION_MINOR == 1 && OBX_VERSION_PATCH == 0 , // NOLINT
38
38
"Versions of objectbox.h and objectbox-sync.h files do not match, please update" );
39
39
#endif
40
40
@@ -56,11 +56,19 @@ typedef struct OBX_sync OBX_sync;
56
56
/// specifies a generic client-side credential type.
57
57
typedef enum {
58
58
OBXSyncCredentialsType_NONE = 1 ,
59
- OBXSyncCredentialsType_SHARED_SECRET = 2 ,
59
+ OBXSyncCredentialsType_SHARED_SECRET = 2 , ///< Deprecated, replaced by SHARED_SECRET_SIPPED
60
60
OBXSyncCredentialsType_GOOGLE_AUTH = 3 ,
61
- OBXSyncCredentialsType_SHARED_SECRET_SIPPED = 4 ,
62
- OBXSyncCredentialsType_OBX_ADMIN_USER = 5 ,
63
- OBXSyncCredentialsType_USER_PASSWORD = 6 ,
61
+ OBXSyncCredentialsType_SHARED_SECRET_SIPPED = 4 , ///< Uses shared secret to create a hashed credential.
62
+ OBXSyncCredentialsType_OBX_ADMIN_USER = 5 , ///< ObjectBox admin users (username/password)
63
+ OBXSyncCredentialsType_USER_PASSWORD = 6 , ///< Generic credential type suitable for ObjectBox admin
64
+ ///< (and possibly others in the future)
65
+ OBXSyncCredentialsType_JWT_ID = 7 , ///< JSON Web Token (JWT): an ID token that typically provides identity
66
+ ///< information about the authenticated user.
67
+ OBXSyncCredentialsType_JWT_ACCESS = 8 , ///< JSON Web Token (JWT): an access token that is used to access resources.
68
+ OBXSyncCredentialsType_JWT_REFRESH = 9 , ///< JSON Web Token (JWT): a refresh token that is used to obtain a new
69
+ ///< access token.
70
+ OBXSyncCredentialsType_JWT_CUSTOM = 10 , ///< JSON Web Token (JWT): a token that is neither an ID, access,
71
+ ///< nor refresh token.
64
72
} OBXSyncCredentialsType ;
65
73
66
74
// TODO sync prefix
@@ -194,8 +202,11 @@ OBX_C_API OBX_sync* obx_sync_urls(OBX_store* store, const char* server_urls[], s
194
202
OBX_C_API obx_err obx_sync_close (OBX_sync * sync );
195
203
196
204
/// Sets credentials to authenticate the client with the server.
197
- /// See OBXSyncCredentialsType for available options.
198
- /// The accepted OBXSyncCredentials type depends on your sync-server configuration.
205
+ /// Any credentials that were set before are replaced;
206
+ /// if you want to pass multiple credentials, use obx_sync_credentials_add() instead.
207
+ /// If the client was waiting for credentials, this can trigger a reconnection/login attempt.
208
+ /// @param type See OBXSyncCredentialsType for available options.
209
+ /// The accepted OBXSyncCredentials type depends on your sync-server configuration.
199
210
/// @param data may be NULL in combination with OBXSyncCredentialsType_NONE
200
211
OBX_C_API obx_err obx_sync_credentials (OBX_sync * sync , OBXSyncCredentialsType type , const uint8_t * data , size_t size );
201
212
@@ -207,6 +218,29 @@ OBX_C_API obx_err obx_sync_credentials(OBX_sync* sync, OBXSyncCredentialsType ty
207
218
OBX_C_API obx_err obx_sync_credentials_user_password (OBX_sync * sync , OBXSyncCredentialsType type , const char * username ,
208
219
const char * password );
209
220
221
+ /// For authentication with multiple credentials, collect credentials by calling this function multiple times.
222
+ /// When adding the last credentials element, the "complete" flag must be set to true.
223
+ /// When completed, it will "activate" the collected credentials and replace any previously set credentials and
224
+ /// potentially trigger a reconnection/login attempt.
225
+ /// @param type See OBXSyncCredentialsType for available options.
226
+ /// The accepted OBXSyncCredentials type depends on your sync-server configuration.
227
+ /// @param data non-NULL (OBXSyncCredentialsType_NONE is not allowed)
228
+ /// @param complete set to true when adding the last credentials element to activate the set of credentials
229
+ OBX_C_API obx_err obx_sync_credentials_add (OBX_sync * sync , OBXSyncCredentialsType type , const uint8_t * data , size_t size ,
230
+ bool complete );
231
+
232
+ /// For authentication with multiple credentials, collect credentials by calling this function multiple times.
233
+ /// When adding the last credentials element, the "complete" flag must be set to true.
234
+ /// When completed, it will "activate" the collected credentials and replace any previously set credentials and
235
+ /// potentially trigger a reconnection/login attempt.
236
+ /// @param type See OBXSyncCredentialsType for available options.
237
+ /// The accepted OBXSyncCredentials type depends on your sync-server configuration.
238
+ /// @param username non-NULL
239
+ /// @param password non-NULL
240
+ /// @param complete set to true when adding the last credentials element to activate the set of credentials
241
+ OBX_C_API obx_err obx_sync_credentials_add_user_password (OBX_sync * sync , OBXSyncCredentialsType type ,
242
+ const char * username , const char * password , bool complete );
243
+
210
244
/// Configures the maximum number of outgoing TX messages that can be sent without an ACK from the server.
211
245
/// @returns OBX_ERROR_ILLEGAL_ARGUMENT if value is not in the range 1-20
212
246
OBX_C_API obx_err obx_sync_max_messages_in_flight (OBX_sync * sync , int value );
@@ -374,9 +408,9 @@ OBX_C_API void obx_sync_listener_msg_objects(OBX_sync* sync, OBX_sync_listener_m
374
408
void * listener_arg );
375
409
376
410
/// Set or overwrite a previously set 'error' listener - provides information about occurred sync-level errors.
377
- /// @param listener set NULL to reset
411
+ /// @param listener The callback to receive sync errors. Set to NULL to reset.
378
412
/// @param listener_arg is a pass-through argument passed to the listener
379
- OBX_C_API void obx_sync_listener_error (OBX_sync * sync , OBX_sync_listener_error * error , void * listener_arg );
413
+ OBX_C_API void obx_sync_listener_error (OBX_sync * sync , OBX_sync_listener_error * listener , void * listener_arg );
380
414
381
415
//----------------------------------------------
382
416
// Sync Stats
@@ -702,7 +736,7 @@ typedef enum {
702
736
703
737
/// Get u64 value for sync server statistics.
704
738
/// @param counter_type the counter value to be read (make sure to choose a uint64_t (u64) metric value type).
705
- /// @param out_count receives the counter value.
739
+ /// @param out_value receives the counter value.
706
740
/// @return OBX_SUCCESS if the counter has been successfully retrieved.
707
741
/// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
708
742
/// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
@@ -711,7 +745,7 @@ OBX_C_API obx_err obx_sync_server_stats_u64(OBX_sync_server* server, OBXSyncServ
711
745
712
746
/// Get double value for sync server statistics.
713
747
/// @param counter_type the counter value to be read (make sure to use a double (f64) metric value type).
714
- /// @param out_count receives the counter value.
748
+ /// @param out_value receives the counter value.
715
749
/// @return OBX_SUCCESS if the counter has been successfully retrieved.
716
750
/// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
717
751
/// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
@@ -785,7 +819,7 @@ typedef void OBX_custom_msg_server_func_client_connection_close(void* server_use
785
819
/// Callback to shutdown and free all resources associated with the sync client connection to the custom server.
786
820
/// Note that the custom server may already have been shutdown at this point (e.g. no server user data is supplied).
787
821
/// Must be provided to implement a custom server. See notes on OBX_custom_msg_server_functions for more details.
788
- /// @param server_user_data User supplied data returned by the function that created the server
822
+ /// @param connection_user_data User supplied data returned by the function that created the server
789
823
typedef void OBX_custom_msg_server_func_client_connection_shutdown (void * connection_user_data );
790
824
791
825
/// Struct of the custom server function callbacks. In order to implement the custom server, you must provide
0 commit comments