1 /* init.c --- Initialization functions for the Shisa library.
2 * Copyright (C) 2002, 2003, 2006 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 * Initializes the Shisa library. If this function fails, it may
28 * print diagnostic errors to stderr.
30 * Return value: Returns Shisa library handle, or %NULL on error.
37 dbh
= xcalloc (1, sizeof (*dbh
));
39 bindtextdomain (PACKAGE
, LOCALEDIR
);
47 * @handle: shisa handle as allocated by shisa().
49 * Deallocates the shisa library handle. The handle must not be used
50 * in any calls to shisa functions after this.
53 shisa_done (Shisa
* dbh
)
58 for (i
= 0, db
= dbh
->dbs
; i
< dbh
->ndbs
; i
++, db
++)
59 db
->backend
->done (dbh
, db
->state
);
69 * @dbh: pointer to library handle to be created.
71 * Create a Shisa library handle, using shisa(), and read the system
72 * configuration file from their default locations. The paths to the
73 * default system configuration file is decided at compile time
74 * ($sysconfdir/shisa.conf).
76 * The handle is allocated regardless of return values, except for
77 * SHISA_INIT_ERROR which indicates a problem allocating the handle.
78 * (The other error conditions comes from reading the files.)
80 * Return value: Returns %SHISA_OK iff successful.
83 shisa_init (Shisa
** dbh
)
85 return shisa_init_with_paths (dbh
, NULL
);
89 * shisa_init_with_paths:
90 * @dbh: pointer to library handle to be created.
91 * @file: Filename of system configuration, or NULL.
93 * Create a Shisa library handle, using shisa(), and read the system
94 * configuration file indicated location (or the default location, if
95 * %NULL). The paths to the default system configuration file is
96 * decided at compile time ($sysconfdir/shisa.conf).
98 * The handle is allocated regardless of return values, except for
99 * SHISA_INIT_ERROR which indicates a problem allocating the handle.
100 * (The other error conditions comes from reading the files.)
102 * Return value: Returns %SHISA_OK iff successful.
105 shisa_init_with_paths (Shisa
** dbh
, const char *file
)
109 if (!dbh
|| !(*dbh
= shisa ()))
110 return SHISA_INIT_ERROR
;
113 file
= shisa_cfg_default_systemfile (*dbh
);
115 rc
= shisa_cfg_from_file (*dbh
, file
);
116 if (rc
!= SHISA_OK
&& rc
!= SHISA_CFG_NO_FILE
)
119 if ((*dbh
)->ndbs
== 0)
121 rc
= shisa_cfg (*dbh
, "db file " DEFAULTDBPATH
);