opsick
db.h
Go to the documentation of this file.
1/*
2 Copyright 2020 Raphael Beck
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef OPSICK_DB_H
18#define OPSICK_DB_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <stddef.h>
25#include <stdint.h>
26#include <libpq-fe.h>
27
28#include "user.h"
29
42int opsick_db_init(const char* dbconn_filepath);
43
49
54void opsick_db_disconnect(PGconn* dbconn);
55
62
68
74
80
87int opsick_db_does_user_id_exist(PGconn* dbconn, uint64_t user_id);
88
101int opsick_db_create_user(PGconn* dbconn, const char* pw, uint64_t exp_utc, const char* public_key_ed25519, const char* encrypted_private_key_ed25519, const char* public_key_curve448, const char* encrypted_private_key_curve448, uint64_t* out_user_id);
102
109int opsick_db_delete_user(PGconn* dbconn, uint64_t user_id);
110
116uint64_t opsick_db_count_users(PGconn* dbconn);
117
125int opsick_db_get_user_metadata(PGconn* db, uint64_t user_id, struct opsick_user_metadata* out_user_metadata);
126
134int opsick_db_set_user_pw(PGconn* dbconn, uint64_t user_id, const char* new_pw);
135
143int opsick_db_set_user_totps(PGconn* dbconn, uint64_t user_id, const char* new_totps);
144
153int opsick_db_get_user_body(PGconn* dbconn, uint64_t user_id, char** out_body, size_t* out_body_length);
154
162int opsick_db_set_user_body(PGconn* dbconn, uint64_t user_id, const char* body);
163
171int opsick_db_set_user_exp(PGconn* dbconn, uint64_t user_id, uint64_t new_exp);
172
183int opsick_db_set_user_keys(PGconn* dbconn, uint64_t user_id, const char* new_pubkey_ed25519, const char* new_prvkey_ed25519, const char* new_pubkey_curve448, const char* new_prvkey_curve448);
184
189
190#ifdef __cplusplus
191} // extern "C"
192#endif
193
194#endif // OPSICK_DB_H
int opsick_db_set_user_body(PGconn *dbconn, uint64_t user_id, const char *body)
int opsick_db_get_user_body(PGconn *dbconn, uint64_t user_id, char **out_body, size_t *out_body_length)
void opsick_db_last_128_bytes_of_ciphertext(uint8_t out[128])
uint64_t opsick_db_count_users(PGconn *dbconn)
int opsick_db_init(const char *dbconn_filepath)
uint64_t opsick_db_get_last_db_schema_version_nr_lookup()
void opsick_db_disconnect(PGconn *dbconn)
uint64_t opsick_db_get_last_used_userid()
int opsick_db_delete_user(PGconn *dbconn, uint64_t user_id)
uint64_t opsick_db_get_schema_version_number()
int opsick_db_set_user_totps(PGconn *dbconn, uint64_t user_id, const char *new_totps)
int opsick_db_create_user(PGconn *dbconn, const char *pw, uint64_t exp_utc, const char *public_key_ed25519, const char *encrypted_private_key_ed25519, const char *public_key_curve448, const char *encrypted_private_key_curve448, uint64_t *out_user_id)
int opsick_db_set_user_exp(PGconn *dbconn, uint64_t user_id, uint64_t new_exp)
void opsick_db_free()
PGconn * opsick_db_connect()
int opsick_db_get_user_metadata(PGconn *db, uint64_t user_id, struct opsick_user_metadata *out_user_metadata)
int opsick_db_does_user_id_exist(PGconn *dbconn, uint64_t user_id)
int opsick_db_set_user_pw(PGconn *dbconn, uint64_t user_id, const char *new_pw)
int opsick_db_set_user_keys(PGconn *dbconn, uint64_t user_id, const char *new_pubkey_ed25519, const char *new_prvkey_ed25519, const char *new_pubkey_curve448, const char *new_prvkey_curve448)
Definition: user.h:37
Contains the opsick_user_metadata struct.