xref: /netbsd-src/external/bsd/iscsi/dist/include/conffile.h (revision 5e01dafb5c1f3a68ee2f80136c3b6043ad89a0f3)
1 /* $NetBSD: conffile.h,v 1.3 2009/06/30 02:44:52 agc Exp $ */
2 
3 /*
4  * Copyright � 2006 Alistair Crooks.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  *    products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #ifndef CONFFILE_H_
31 #define CONFFILE_H_	1
32 
33 /* split routines */
34 
35 #include <sys/param.h>
36 
37 #include <stdio.h>
38 #include <time.h>
39 
40 #include "defs.h"
41 
42 DEFINE_ARRAY(strv_t, char *);
43 
44 /* this struct describes a configuration file */
45 typedef struct conffile_t {
46 	FILE		*fp;			/* in-core file pointer */
47 	char		 name[MAXPATHLEN];	/* name of file */
48 	int	 	 lineno;		/* current line number */
49 	int		 readonly;		/* nonzero if file is readonly */
50 	const char	*sep;			/* set of separators */
51 	const char	*comment;		/* set of comment characters */
52 } conffile_t;
53 
54 /* this struct describes an entry in the configuration file */
55 typedef struct ent_t {
56 	char		buf[BUFSIZ];		/* buffer with entry contents */
57 	strv_t		sv;			/* split up string dynamic array */
58 } ent_t;
59 
60 int conffile_open(conffile_t *, const char *, const char *, const char *, const char *);
61 int conffile_split(conffile_t *, ent_t *, char *);
62 int conffile_getent(conffile_t *, ent_t *);
63 int conffile_get_by_field(conffile_t *, ent_t *, int, char *);
64 int conffile_putent(conffile_t *, int, char *, char *);
65 int conffile_get_lineno(conffile_t *);
66 char *conffile_get_name(conffile_t *);
67 void conffile_printent(ent_t *);
68 void conffile_close(conffile_t *);
69 
70 #ifndef PREFIX
71 #define PREFIX	""
72 #endif
73 
74 #ifndef SYSCONFDIR
75 #define SYSCONFDIR	"/etc"
76 #endif
77 
78 #define _PATH_ISCSI_ETC		SYSCONFDIR "/iscsi/"
79 
80 #define _PATH_ISCSI_PASSWD	PREFIX _PATH_ISCSI_ETC "auths"
81 #define	_PATH_ISCSI_TARGETS	PREFIX _PATH_ISCSI_ETC "targets"
82 #define	_PATH_ISCSI_PID_FILE	"/var/run/iscsi-target.pid"
83 
84 #endif
85