1/* 2 * inifile.h 3 * 4 * $Id: inifile.h,v 1.4 2006/01/20 15:58:35 source Exp $ 5 * 6 * Read/Write .ini files 7 * 8 * The iODBC driver manager. 9 * 10 * Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com> 11 * All Rights Reserved. 12 * 13 * This software is released under the terms of either of the following 14 * licenses: 15 * 16 * - GNU Library General Public License (see LICENSE.LGPL) 17 * - The BSD License (see LICENSE.BSD). 18 * 19 * Note that the only valid version of the LGPL license as far as this 20 * project is concerned is the original GNU Library General Public License 21 * Version 2, dated June 1991. 22 * 23 * While not mandated by the BSD license, any patches you make to the 24 * iODBC source code may be contributed back into the iODBC project 25 * at your discretion. Contributions will benefit the Open Source and 26 * Data Access community as a whole. Submissions may be made at: 27 * 28 * http://www.iodbc.org 29 * 30 * 31 * GNU Library Generic Public License Version 2 32 * ============================================ 33 * This library is free software; you can redistribute it and/or 34 * modify it under the terms of the GNU Library General Public 35 * License as published by the Free Software Foundation; only 36 * Version 2 of the License dated June 1991. 37 * 38 * This library is distributed in the hope that it will be useful, 39 * but WITHOUT ANY WARRANTY; without even the implied warranty of 40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 41 * Library General Public License for more details. 42 * 43 * You should have received a copy of the GNU Library General Public 44 * License along with this library; if not, write to the Free 45 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 46 * 47 * 48 * The BSD License 49 * =============== 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in 58 * the documentation and/or other materials provided with the 59 * distribution. 60 * 3. Neither the name of OpenLink Software Inc. nor the names of its 61 * contributors may be used to endorse or promote products derived 62 * from this software without specific prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 65 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 66 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 67 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR 68 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 69 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 70 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 71 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 72 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 73 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 74 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 75 */ 76 77 78#ifndef _INIFILE_H 79#define _INIFILE_H 80 81#include <fcntl.h> 82#ifndef _MAC 83#include <sys/types.h> 84#endif 85 86/* configuration file entry */ 87typedef struct TCFGENTRY 88 { 89 char *section; 90 char *id; 91 char *value; 92 char *comment; 93 unsigned short flags; 94 } 95TCFGENTRY, *PCFGENTRY; 96 97/* values for flags */ 98#define CFE_MUST_FREE_SECTION 0x8000 99#define CFE_MUST_FREE_ID 0x4000 100#define CFE_MUST_FREE_VALUE 0x2000 101#define CFE_MUST_FREE_COMMENT 0x1000 102 103/* configuration file */ 104typedef struct TCFGDATA 105 { 106 char *fileName; /* Current file name */ 107 108 int dirty; /* Did we make modifications? */ 109 110 char *image; /* In-memory copy of the file */ 111 size_t size; /* Size of this copy (excl. \0) */ 112 time_t mtime; /* Modification time */ 113 114 unsigned int numEntries; 115 unsigned int maxEntries; 116 PCFGENTRY entries; 117 118 /* Compatibility */ 119 unsigned int cursor; 120 char *section; 121 char *id; 122 char *value; 123 char *comment; 124 unsigned short flags; 125 126 } 127TCONFIG, *PCONFIG; 128 129#define CFG_VALID 0x8000 130#define CFG_EOF 0x4000 131 132#define CFG_ERROR 0x0000 133#define CFG_SECTION 0x0001 134#define CFG_DEFINE 0x0002 135#define CFG_CONTINUE 0x0003 136 137#define CFG_TYPEMASK 0x000F 138#define CFG_TYPE(X) ((X) & CFG_TYPEMASK) 139#define _iodbcdm_cfg_valid(X) ((X) != NULL && ((X)->flags & CFG_VALID)) 140#define _iodbcdm_cfg_eof(X) ((X)->flags & CFG_EOF) 141#define _iodbcdm_cfg_section(X) (CFG_TYPE((X)->flags) == CFG_SECTION) 142#define _iodbcdm_cfg_define(X) (CFG_TYPE((X)->flags) == CFG_DEFINE) 143#define _iodbcdm_cfg_cont(X) (CFG_TYPE((X)->flags) == CFG_CONTINUE) 144 145int _iodbcdm_cfg_init (PCONFIG * ppconf, const char *filename, int doCreate); 146int _iodbcdm_cfg_done (PCONFIG pconfig); 147int _iodbcdm_cfg_freeimage (PCONFIG pconfig); 148int _iodbcdm_cfg_refresh (PCONFIG pconfig); 149int _iodbcdm_cfg_storeentry (PCONFIG pconfig, char *section, char *id, 150 char *value, char *comment, int dynamic); 151int _iodbcdm_cfg_rewind (PCONFIG pconfig); 152int _iodbcdm_cfg_nextentry (PCONFIG pconfig); 153int _iodbcdm_cfg_find (PCONFIG pconfig, char *section, char *id); 154int _iodbcdm_cfg_next_section (PCONFIG pconfig); 155 156int _iodbcdm_cfg_write (PCONFIG pconfig, char *section, char *id, char *value); 157int _iodbcdm_cfg_commit (PCONFIG pconfig); 158int _iodbcdm_cfg_getstring (PCONFIG pconfig, char *section, char *id, 159 char **valptr); 160int _iodbcdm_cfg_getlong (PCONFIG pconfig, char *section, char *id, 161 long *valptr); 162int _iodbcdm_cfg_getshort (PCONFIG pconfig, char *section, char *id, 163 short *valptr); 164int _iodbcdm_cfg_search_init (PCONFIG * ppconf, const char *filename, 165 int doCreate); 166int _iodbcdm_list_entries (PCONFIG pCfg, LPCSTR lpszSection, 167 LPSTR lpszRetBuffer, int cbRetBuffer); 168int _iodbcdm_list_sections (PCONFIG pCfg, LPSTR lpszRetBuffer, int cbRetBuffer); 169BOOL do_create_dsns (PCONFIG pCfg, PCONFIG pInfCfg, LPSTR szDriver, 170 LPSTR szDSNS, LPSTR szDiz); 171BOOL install_from_ini (PCONFIG pCfg, PCONFIG pOdbcCfg, LPSTR szInfFile, 172 LPSTR szDriver, BOOL drivers); 173int install_from_string (PCONFIG pCfg, PCONFIG pOdbcCfg, LPSTR lpszDriver, 174 BOOL drivers); 175 176#endif /* _INIFILE_H */ 177