1 /* GNU Mailutils -- a suite of utilities for electronic mail 2 Copyright (C) 2011-2021 Free Software Foundation, Inc. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 3 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General 15 Public License along with this library. If not, see 16 <http://www.gnu.org/licenses/>. */ 17 18 #ifndef _MAILUTILS_DBM_H 19 #define _MAILUTILS_DBM_H 20 21 #include <mailutils/types.h> 22 23 struct mu_dbm_datum 24 { 25 char *mu_dptr; /* Data pointer */ 26 size_t mu_dsize; /* Data size */ 27 void *mu_data; /* Implementation-dependent data */ 28 struct mu_dbm_impl *mu_sys; /* Pointer to implementation */ 29 }; 30 31 struct mu_dbm_impl 32 { 33 char *_dbm_name; 34 int (*_dbm_file_safety) (mu_dbm_file_t db, int mode, uid_t owner); 35 int (*_dbm_get_fd) (mu_dbm_file_t db, int *pag, int *dir); 36 int (*_dbm_open) (mu_dbm_file_t db, int flags, int mode); 37 int (*_dbm_close) (mu_dbm_file_t db); 38 int (*_dbm_fetch) (mu_dbm_file_t db, struct mu_dbm_datum const *key, 39 struct mu_dbm_datum *ret); 40 int (*_dbm_store) (mu_dbm_file_t db, struct mu_dbm_datum const *key, 41 struct mu_dbm_datum const *contents, int replace); 42 int (*_dbm_delete) (mu_dbm_file_t db, 43 struct mu_dbm_datum const *key); 44 int (*_dbm_firstkey) (mu_dbm_file_t db, struct mu_dbm_datum *ret); 45 int (*_dbm_nextkey) (mu_dbm_file_t db, struct mu_dbm_datum *ret); 46 void (*_dbm_datum_free) (struct mu_dbm_datum *datum); 47 char const *(*_dbm_strerror) (mu_dbm_file_t db); 48 }; 49 50 extern mu_url_t mu_dbm_hint; 51 52 void mu_dbm_init (void); 53 mu_url_t mu_dbm_get_hint (void); 54 55 int mu_dbm_register (struct mu_dbm_impl *impl); 56 int mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db, int defsafety); 57 int mu_dbm_create (char *name, mu_dbm_file_t *db, int defsafety); 58 int mu_dbm_close (mu_dbm_file_t db); 59 void mu_dbm_datum_free (struct mu_dbm_datum *datum); 60 int mu_dbm_delete (mu_dbm_file_t db, struct mu_dbm_datum const *key); 61 void mu_dbm_destroy (mu_dbm_file_t *pdb); 62 int mu_dbm_fetch (mu_dbm_file_t db, struct mu_dbm_datum const *key, 63 struct mu_dbm_datum *ret); 64 int mu_dbm_store (mu_dbm_file_t db, struct mu_dbm_datum const *key, 65 struct mu_dbm_datum const *contents, int replace); 66 int mu_dbm_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret); 67 int mu_dbm_nextkey (mu_dbm_file_t db, struct mu_dbm_datum *ret); 68 int mu_dbm_open (mu_dbm_file_t db, int flags, int mode); 69 int mu_dbm_safety_get_owner (mu_dbm_file_t db, uid_t *uid); 70 int mu_dbm_safety_get_flags (mu_dbm_file_t db, int *flags); 71 int mu_dbm_safety_set_owner (mu_dbm_file_t db, uid_t uid); 72 int mu_dbm_safety_set_flags (mu_dbm_file_t db, int flags); 73 int mu_dbm_safety_check (mu_dbm_file_t db); 74 char const *mu_dbm_strerror (mu_dbm_file_t db); 75 int mu_dbm_get_fd (mu_dbm_file_t db, int *pag, int *dir); 76 int mu_dbm_get_name (mu_dbm_file_t db, const char **pname); 77 78 int mu_dbm_impl_iterator (mu_iterator_t *itr); 79 80 #endif 81