diff options
author | Daiki Ueno <dueno@redhat.com> | 2018-11-01 15:37:42 +0100 |
---|---|---|
committer | Daiki Ueno <dueno@redhat.com> | 2018-11-12 14:08:45 +0100 |
commit | 8ada9c280c9044644dfad1f234e3da32f0df86a0 (patch) | |
tree | f60f3a15e2d40fe02c27e5487a32a697bdb6ca34 /lib | |
parent | 0a590e15e17383c5b18650465266da5f4cfd2af1 (diff) | |
download | gnutls-8ada9c280c9044644dfad1f234e3da32f0df86a0.tar.gz |
db: introduce gnutls_db_set_add_function
This adds a way to store an entry if it is not found in the database,
so that the implementation can provide atomic test-and-set.
Signed-off-by: Daiki Ueno <dueno@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/db.c | 23 | ||||
-rw-r--r-- | lib/errors.c | 1 | ||||
-rw-r--r-- | lib/gnutls_int.h | 1 | ||||
-rw-r--r-- | lib/includes/gnutls/gnutls.h.in | 5 | ||||
-rw-r--r-- | lib/libgnutls.map | 1 |
5 files changed, 31 insertions, 0 deletions
@@ -56,6 +56,29 @@ gnutls_db_set_retrieve_function(gnutls_session_t session, } /** + * gnutls_db_set_add_function: + * @session: is a #gnutls_session_t type. + * @add_func: is the function. + * + * Sets the function that will be used to store an entry if it is not + * already present in the resumed sessions database. This function returns 0 + * if the entry is successfully stored, and a negative error code + * otherwise. In particular, if the entry is found in the database, + * it returns %GNUTLS_E_DB_ENTRY_EXISTS. + * + * The first argument to @add_func will be null unless + * gnutls_db_set_ptr() has been called. + * + * Since: 3.6.5 + **/ +void +gnutls_db_set_add_function(gnutls_session_t session, + gnutls_db_add_func add_func) +{ + session->internals.db_add_func = add_func; +} + +/** * gnutls_db_set_remove_function: * @session: is a #gnutls_session_t type. * @rem_func: is the function. diff --git a/lib/errors.c b/lib/errors.c index e579f46852..a83a49eeab 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -193,6 +193,7 @@ static const gnutls_error_entry error_entries[] = { ("TLS Application data were received, while expecting handshake data."), GNUTLS_E_GOT_APPLICATION_DATA), ERROR_ENTRY(N_("Error in Database backend."), GNUTLS_E_DB_ERROR), + ERROR_ENTRY(N_("The Database entry already exists."), GNUTLS_E_DB_ENTRY_EXISTS), ERROR_ENTRY(N_("The certificate type is not supported."), GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE), ERROR_ENTRY(N_ diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 73fcfcc9c8..42d68d4398 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -1216,6 +1216,7 @@ typedef struct { gnutls_db_store_func db_store_func; gnutls_db_retr_func db_retrieve_func; gnutls_db_remove_func db_remove_func; + gnutls_db_add_func db_add_func; void *db_ptr; /* post client hello callback (server side only) diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in index 1c07ff33a5..3a4d01d442 100644 --- a/lib/includes/gnutls/gnutls.h.in +++ b/lib/includes/gnutls/gnutls.h.in @@ -1783,6 +1783,8 @@ typedef int (*gnutls_db_store_func) (void *, gnutls_datum_t key, gnutls_datum_t data); typedef int (*gnutls_db_remove_func) (void *, gnutls_datum_t key); typedef gnutls_datum_t(*gnutls_db_retr_func) (void *, gnutls_datum_t key); +typedef int (*gnutls_db_add_func) (void *, gnutls_datum_t key, + gnutls_datum_t data); void gnutls_db_set_cache_expiration(gnutls_session_t session, int seconds); unsigned gnutls_db_get_default_cache_expiration(void); @@ -1794,6 +1796,8 @@ void gnutls_db_set_remove_function(gnutls_session_t session, gnutls_db_remove_func rem_func); void gnutls_db_set_store_function(gnutls_session_t session, gnutls_db_store_func store_func); +void gnutls_db_set_add_function(gnutls_session_t session, + gnutls_db_add_func add_func); void gnutls_db_set_ptr(gnutls_session_t session, void *ptr); void *gnutls_db_get_ptr(gnutls_session_t session); int gnutls_db_check_entry(gnutls_session_t session, @@ -3265,6 +3269,7 @@ void gnutls_fips140_set_mode(gnutls_fips_mode_t mode, unsigned flags); #define GNUTLS_E_TOO_MANY_MATCHES -425 #define GNUTLS_E_CRL_VERIFICATION_ERROR -426 #define GNUTLS_E_MISSING_EXTENSION -427 +#define GNUTLS_E_DB_ENTRY_EXISTS -428 #define GNUTLS_E_UNIMPLEMENTED_FEATURE -1250 diff --git a/lib/libgnutls.map b/lib/libgnutls.map index cfa87a6b26..a4aaf11ca1 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -1255,6 +1255,7 @@ GNUTLS_3_6_5 gnutls_record_send_early_data; gnutls_record_recv_early_data; gnutls_db_check_entry_expire_time; + gnutls_db_set_add_function; } GNUTLS_3_6_4; GNUTLS_FIPS140_3_4 { |