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