diff options
author | Simon Josefsson <simon@josefsson.org> | 2005-11-07 23:27:56 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2005-11-07 23:27:56 +0000 |
commit | a5891d75997c9529b9fc5c273df8bd0df4093cd0 (patch) | |
tree | fd6eec448a88c5eb891cc145921c5793662da604 /lib/gnutls_db.c | |
parent | af21484a8daf15da48f7d00c4fe632708a757a64 (diff) | |
download | gnutls-a5891d75997c9529b9fc5c273df8bd0df4093cd0.tar.gz |
Use GNU coding style.
Diffstat (limited to 'lib/gnutls_db.c')
-rw-r--r-- | lib/gnutls_db.c | 293 |
1 files changed, 157 insertions, 136 deletions
diff --git a/lib/gnutls_db.c b/lib/gnutls_db.c index 29af963bf3..75be69303d 100644 --- a/lib/gnutls_db.c +++ b/lib/gnutls_db.c @@ -50,10 +50,11 @@ * has been called. * **/ -void gnutls_db_set_retrieve_function(gnutls_session_t session, - gnutls_db_retr_func retr_func) +void +gnutls_db_set_retrieve_function (gnutls_session_t session, + gnutls_db_retr_func retr_func) { - session->internals.db_retrieve_func = retr_func; + session->internals.db_retrieve_func = retr_func; } /** @@ -68,10 +69,11 @@ void gnutls_db_set_retrieve_function(gnutls_session_t session, * has been called. * **/ -void gnutls_db_set_remove_function(gnutls_session_t session, - gnutls_db_remove_func rem_func) +void +gnutls_db_set_remove_function (gnutls_session_t session, + gnutls_db_remove_func rem_func) { - session->internals.db_remove_func = rem_func; + session->internals.db_remove_func = rem_func; } /** @@ -86,10 +88,11 @@ void gnutls_db_set_remove_function(gnutls_session_t session, * has been called. * **/ -void gnutls_db_set_store_function(gnutls_session_t session, - gnutls_db_store_func store_func) +void +gnutls_db_set_store_function (gnutls_session_t session, + gnutls_db_store_func store_func) { - session->internals.db_store_func = store_func; + session->internals.db_store_func = store_func; } /** @@ -101,9 +104,10 @@ void gnutls_db_set_store_function(gnutls_session_t session, * the first argument. * **/ -void gnutls_db_set_ptr(gnutls_session_t session, void *ptr) +void +gnutls_db_set_ptr (gnutls_session_t session, void *ptr) { - session->internals.db_ptr = ptr; + session->internals.db_ptr = ptr; } /** @@ -114,9 +118,10 @@ void gnutls_db_set_ptr(gnutls_session_t session, void *ptr) * the first argument. * **/ -void *gnutls_db_get_ptr(gnutls_session_t session) +void * +gnutls_db_get_ptr (gnutls_session_t session) { - return session->internals.db_ptr; + return session->internals.db_ptr; } /** @@ -127,9 +132,10 @@ void *gnutls_db_get_ptr(gnutls_session_t session) * Sets the expiration time for resumed sessions. The default is 3600 (one hour) * at the time writing this. **/ -void gnutls_db_set_cache_expiration(gnutls_session_t session, int seconds) +void +gnutls_db_set_cache_expiration (gnutls_session_t session, int seconds) { - session->internals.expire_time = seconds; + session->internals.expire_time = seconds; } /** @@ -143,201 +149,216 @@ void gnutls_db_set_cache_expiration(gnutls_session_t session, int seconds) * backend. * **/ -int gnutls_db_check_entry(gnutls_session_t session, - gnutls_datum_t session_entry) +int +gnutls_db_check_entry (gnutls_session_t session, gnutls_datum_t session_entry) { - time_t timestamp; + time_t timestamp; - timestamp = time(0); + timestamp = time (0); - if (session_entry.data != NULL) - if (timestamp - - ((security_parameters_st *) (session_entry.data))->timestamp <= - session->internals.expire_time - || ((security_parameters_st *) (session_entry.data))-> - timestamp > timestamp - || ((security_parameters_st *) (session_entry.data))-> - timestamp == 0) - return GNUTLS_E_EXPIRED; + if (session_entry.data != NULL) + if (timestamp - + ((security_parameters_st *) (session_entry.data))->timestamp <= + session->internals.expire_time + || ((security_parameters_st *) (session_entry.data))-> + timestamp > timestamp + || ((security_parameters_st *) (session_entry.data))->timestamp == 0) + return GNUTLS_E_EXPIRED; - return 0; + return 0; } /* The format of storing data is: * (forget it). Check gnutls_session_pack.c */ -int _gnutls_server_register_current_session(gnutls_session_t session) +int +_gnutls_server_register_current_session (gnutls_session_t session) { - gnutls_datum_t key; - gnutls_datum_t content; - int ret = 0; + gnutls_datum_t key; + gnutls_datum_t content; + int ret = 0; - key.data = session->security_parameters.session_id; - key.size = session->security_parameters.session_id_size; + key.data = session->security_parameters.session_id; + key.size = session->security_parameters.session_id_size; - if (session->internals.resumable == RESUME_FALSE) { - gnutls_assert(); - return GNUTLS_E_INVALID_SESSION; + if (session->internals.resumable == RESUME_FALSE) + { + gnutls_assert (); + return GNUTLS_E_INVALID_SESSION; } - if (session->security_parameters.session_id == NULL - || session->security_parameters.session_id_size == 0) { - gnutls_assert(); - return GNUTLS_E_INVALID_SESSION; + if (session->security_parameters.session_id == NULL + || session->security_parameters.session_id_size == 0) + { + gnutls_assert (); + return GNUTLS_E_INVALID_SESSION; } /* copy data */ - ret = _gnutls_session_pack(session, &content); - if (ret < 0) { - gnutls_assert(); - return ret; + ret = _gnutls_session_pack (session, &content); + if (ret < 0) + { + gnutls_assert (); + return ret; } - ret = _gnutls_store_session(session, key, content); - _gnutls_free_datum( &content); + ret = _gnutls_store_session (session, key, content); + _gnutls_free_datum (&content); - return ret; + return ret; } /* Checks if both db_store and db_retrieve functions have * been set up. */ -static int _gnutls_db_func_is_ok(gnutls_session_t session) +static int +_gnutls_db_func_is_ok (gnutls_session_t session) { - if (session->internals.db_store_func != NULL && - session->internals.db_retrieve_func != NULL && - session->internals.db_remove_func != NULL) - return 0; - else - return GNUTLS_E_DB_ERROR; + if (session->internals.db_store_func != NULL && + session->internals.db_retrieve_func != NULL && + session->internals.db_remove_func != NULL) + return 0; + else + return GNUTLS_E_DB_ERROR; } -int _gnutls_server_restore_session(gnutls_session_t session, - uint8 * session_id, int session_id_size) +int +_gnutls_server_restore_session (gnutls_session_t session, + uint8 * session_id, int session_id_size) { - gnutls_datum_t data; - gnutls_datum_t key; - int ret; + gnutls_datum_t data; + gnutls_datum_t key; + int ret; - key.data = session_id; - key.size = session_id_size; + key.data = session_id; + key.size = session_id_size; - if (_gnutls_db_func_is_ok(session) != 0) { - gnutls_assert(); - return GNUTLS_E_INVALID_SESSION; + if (_gnutls_db_func_is_ok (session) != 0) + { + gnutls_assert (); + return GNUTLS_E_INVALID_SESSION; } - data = _gnutls_retrieve_session(session, key); + data = _gnutls_retrieve_session (session, key); - if (data.data == NULL) { - gnutls_assert(); - return GNUTLS_E_INVALID_SESSION; + if (data.data == NULL) + { + gnutls_assert (); + return GNUTLS_E_INVALID_SESSION; } - /* expiration check is performed inside */ - ret = gnutls_session_set_data(session, data.data, data.size); - if (ret < 0) { - gnutls_assert(); - return ret; + /* expiration check is performed inside */ + ret = gnutls_session_set_data (session, data.data, data.size); + if (ret < 0) + { + gnutls_assert (); + return ret; } - gnutls_free(data.data); + gnutls_free (data.data); - return 0; + return 0; } -int _gnutls_db_remove_session(gnutls_session_t session, uint8 * session_id, - int session_id_size) +int +_gnutls_db_remove_session (gnutls_session_t session, uint8 * session_id, + int session_id_size) { - gnutls_datum_t key; + gnutls_datum_t key; - key.data = session_id; - key.size = session_id_size; + key.data = session_id; + key.size = session_id_size; - return _gnutls_remove_session(session, key); + return _gnutls_remove_session (session, key); } /* Stores session data to the db backend. */ -int _gnutls_store_session(gnutls_session_t session, - gnutls_datum_t session_id, - gnutls_datum_t session_data) +int +_gnutls_store_session (gnutls_session_t session, + gnutls_datum_t session_id, gnutls_datum_t session_data) { - int ret = 0; + int ret = 0; - if (session->internals.resumable == RESUME_FALSE) { - gnutls_assert(); - return GNUTLS_E_INVALID_SESSION; + if (session->internals.resumable == RESUME_FALSE) + { + gnutls_assert (); + return GNUTLS_E_INVALID_SESSION; } - if (_gnutls_db_func_is_ok(session) != 0) { - return GNUTLS_E_DB_ERROR; + if (_gnutls_db_func_is_ok (session) != 0) + { + return GNUTLS_E_DB_ERROR; } - if (session_id.data == NULL || session_id.size == 0) { - gnutls_assert(); - return GNUTLS_E_INVALID_SESSION; + if (session_id.data == NULL || session_id.size == 0) + { + gnutls_assert (); + return GNUTLS_E_INVALID_SESSION; } - if (session_data.data == NULL || session_data.size == 0) { - gnutls_assert(); - return GNUTLS_E_INVALID_SESSION; + if (session_data.data == NULL || session_data.size == 0) + { + gnutls_assert (); + return GNUTLS_E_INVALID_SESSION; } - /* if we can't read why bother writing? */ + /* if we can't read why bother writing? */ - if (session->internals.db_store_func != NULL) - ret = - session->internals.db_store_func(session->internals.db_ptr, - session_id, session_data); + if (session->internals.db_store_func != NULL) + ret = + session->internals.db_store_func (session->internals.db_ptr, + session_id, session_data); - return (ret == 0 ? ret : GNUTLS_E_DB_ERROR); + return (ret == 0 ? ret : GNUTLS_E_DB_ERROR); } /* Retrieves session data from the db backend. */ -gnutls_datum_t _gnutls_retrieve_session(gnutls_session_t session, - gnutls_datum_t session_id) +gnutls_datum_t +_gnutls_retrieve_session (gnutls_session_t session, gnutls_datum_t session_id) { - gnutls_datum_t ret = { NULL, 0 }; + gnutls_datum_t ret = { NULL, 0 }; - if (session_id.data == NULL || session_id.size == 0) { - gnutls_assert(); - return ret; + if (session_id.data == NULL || session_id.size == 0) + { + gnutls_assert (); + return ret; } - if (session->internals.db_retrieve_func != NULL) - ret = - session->internals.db_retrieve_func(session->internals.db_ptr, - session_id); + if (session->internals.db_retrieve_func != NULL) + ret = + session->internals.db_retrieve_func (session->internals.db_ptr, + session_id); - return ret; + return ret; } /* Removes session data from the db backend. */ -int _gnutls_remove_session(gnutls_session_t session, - gnutls_datum_t session_id) +int +_gnutls_remove_session (gnutls_session_t session, gnutls_datum_t session_id) { - int ret = 0; + int ret = 0; - if (_gnutls_db_func_is_ok(session) != 0) { - return GNUTLS_E_DB_ERROR; + if (_gnutls_db_func_is_ok (session) != 0) + { + return GNUTLS_E_DB_ERROR; } - if (session_id.data == NULL || session_id.size == 0) - return GNUTLS_E_INVALID_SESSION; + if (session_id.data == NULL || session_id.size == 0) + return GNUTLS_E_INVALID_SESSION; - /* if we can't read why bother writing? */ - if (session->internals.db_remove_func != NULL) - ret = - session->internals.db_remove_func(session->internals.db_ptr, - session_id); + /* if we can't read why bother writing? */ + if (session->internals.db_remove_func != NULL) + ret = + session->internals.db_remove_func (session->internals.db_ptr, + session_id); - return (ret == 0 ? ret : GNUTLS_E_DB_ERROR); + return (ret == 0 ? ret : GNUTLS_E_DB_ERROR); } @@ -353,13 +374,13 @@ int _gnutls_remove_session(gnutls_session_t session, * Normally gnutls_deinit() will remove abnormally terminated sessions. * **/ -void gnutls_db_remove_session(gnutls_session_t session) +void +gnutls_db_remove_session (gnutls_session_t session) { - /* if the session has failed abnormally it has - * to be removed from the db - */ - _gnutls_db_remove_session(session, - session->security_parameters.session_id, - session->security_parameters. - session_id_size); + /* if the session has failed abnormally it has + * to be removed from the db + */ + _gnutls_db_remove_session (session, + session->security_parameters.session_id, + session->security_parameters.session_id_size); } |