a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina/*
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina Authors:
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina Pavel Březina <pbrezina@redhat.com>
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina Copyright (C) 2015 Red Hat
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina This program is free software; you can redistribute it and/or modify
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina it under the terms of the GNU General Public License as published by
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina the Free Software Foundation; either version 3 of the License, or
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina (at your option) any later version.
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina This program is distributed in the hope that it will be useful,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina GNU General Public License for more details.
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina You should have received a copy of the GNU General Public License
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina*/
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#ifndef _SSS_COLONDB_H_
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#define _SSS_COLONDB_H_
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#include <stdlib.h>
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#include <stdint.h>
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#include <errno.h>
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#include <talloc.h>
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinastruct sss_colondb;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaenum sss_colondb_mode {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina SSS_COLONDB_READ,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina SSS_COLONDB_WRITE
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina};
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaenum sss_colondb_type {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina SSS_COLONDB_UINT32,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina SSS_COLONDB_STRING,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina SSS_COLONDB_SENTINEL
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina};
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaunion sss_colondb_write_data {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina uint32_t uint32;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina const char *str;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina};
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaunion sss_colondb_read_data {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina uint32_t *uint32;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina const char **str;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina};
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinastruct sss_colondb_write_field {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina enum sss_colondb_type type;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina union sss_colondb_write_data data;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina};
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinastruct sss_colondb_read_field {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina enum sss_colondb_type type;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina union sss_colondb_read_data data;
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina};
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech/**
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * Open colon DB and return connection.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in|out] mem_ctx Memory context. Internal sss_colondb_close() is set
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * on destructor of this memory context.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in] mode Open mode of db: SSS_COLONDB_READ or SSS_COLONDB_WRITE.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in] filename Name of file.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @return Pointer to structure holding DB connection, or NULL if fail.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinastruct sss_colondb *sss_colondb_open(TALLOC_CTX *mem_ctx,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina enum sss_colondb_mode mode,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina const char *filename);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech/**
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * Read line from colon DB.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in|out] mem_ctx Memory context.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in] db Pointer to structure holding DB connection.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in|out] table Array of expected structure of line. It is expected
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * that last item has SSS_COLONDB_SENTINEL type.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @return EOK if success, else error code.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaerrno_t sss_colondb_readline(TALLOC_CTX *mem_ctx,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina struct sss_colondb *db,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina struct sss_colondb_read_field *table);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech/**
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * Write line to colon DB.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in] db Pointer to structure holding DB connection.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @param[in] table Array with data. It is expected that last item has
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * SSS_COLONDB_SENTINEL type.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech * @return EOK if success, else error code.
cf1109e30320a994187edeb438ac7cdc36f0dd2bPetr Cech */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaerrno_t sss_colondb_writeline(struct sss_colondb *db,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina struct sss_colondb_write_field *table);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#endif /* _SSS_COLONDB_H_ */