1 /* init.c --- Initialization functions for the Shisa library.
2 * Copyright (C) 2002, 2003, 2006, 2007 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 * Floor, Boston, MA 02110-1301, USA
28 * Initializes the Shisa library. If this function fails, it may
29 * print diagnostic errors to stderr.
31 * Return value: Returns Shisa library handle, or %NULL on error.
38 dbh
= xcalloc (1, sizeof (*dbh
));
40 bindtextdomain (PACKAGE
, LOCALEDIR
);
48 * @handle: shisa handle as allocated by shisa().
50 * Deallocates the shisa library handle. The handle must not be used
51 * in any calls to shisa functions after this.
54 shisa_done (Shisa
* dbh
)
59 for (i
= 0, db
= dbh
->dbs
; i
< dbh
->ndbs
; i
++, db
++)
60 db
->backend
->done (dbh
, db
->state
);
70 * @dbh: pointer to library handle to be created.
72 * Create a Shisa library handle, using shisa(), and read the system
73 * configuration file from their default locations. The paths to the
74 * default system configuration file is decided at compile time
75 * ($sysconfdir/shisa.conf).
77 * The handle is allocated regardless of return values, except for
78 * SHISA_INIT_ERROR which indicates a problem allocating the handle.
79 * (The other error conditions comes from reading the files.)
81 * Return value: Returns %SHISA_OK iff successful.
84 shisa_init (Shisa
** dbh
)
86 return shisa_init_with_paths (dbh
, NULL
);
90 * shisa_init_with_paths:
91 * @dbh: pointer to library handle to be created.
92 * @file: Filename of system configuration, or NULL.
94 * Create a Shisa library handle, using shisa(), and read the system
95 * configuration file indicated location (or the default location, if
96 * %NULL). The paths to the default system configuration file is
97 * decided at compile time ($sysconfdir/shisa.conf).
99 * The handle is allocated regardless of return values, except for
100 * SHISA_INIT_ERROR which indicates a problem allocating the handle.
101 * (The other error conditions comes from reading the files.)
103 * Return value: Returns %SHISA_OK iff successful.
106 shisa_init_with_paths (Shisa
** dbh
, const char *file
)
110 if (!dbh
|| !(*dbh
= shisa ()))
111 return SHISA_INIT_ERROR
;
114 file
= shisa_cfg_default_systemfile (*dbh
);
116 rc
= shisa_cfg_from_file (*dbh
, file
);
117 if (rc
!= SHISA_OK
&& rc
!= SHISA_CFG_NO_FILE
)
120 if ((*dbh
)->ndbs
== 0)
122 rc
= shisa_cfg (*dbh
, "db file " DEFAULTDBPATH
);