14bff34e3Sthurlow /* 24bff34e3Sthurlow * Copyright (c) 2000, Boris Popov 34bff34e3Sthurlow * All rights reserved. 44bff34e3Sthurlow * 54bff34e3Sthurlow * Redistribution and use in source and binary forms, with or without 64bff34e3Sthurlow * modification, are permitted provided that the following conditions 74bff34e3Sthurlow * are met: 84bff34e3Sthurlow * 1. Redistributions of source code must retain the above copyright 94bff34e3Sthurlow * notice, this list of conditions and the following disclaimer. 104bff34e3Sthurlow * 2. Redistributions in binary form must reproduce the above copyright 114bff34e3Sthurlow * notice, this list of conditions and the following disclaimer in the 124bff34e3Sthurlow * documentation and/or other materials provided with the distribution. 134bff34e3Sthurlow * 3. All advertising materials mentioning features or use of this software 144bff34e3Sthurlow * must display the following acknowledgement: 154bff34e3Sthurlow * This product includes software developed by Boris Popov. 164bff34e3Sthurlow * 4. Neither the name of the author nor the names of any co-contributors 174bff34e3Sthurlow * may be used to endorse or promote products derived from this software 184bff34e3Sthurlow * without specific prior written permission. 194bff34e3Sthurlow * 204bff34e3Sthurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 214bff34e3Sthurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224bff34e3Sthurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234bff34e3Sthurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 244bff34e3Sthurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254bff34e3Sthurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264bff34e3Sthurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274bff34e3Sthurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284bff34e3Sthurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294bff34e3Sthurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304bff34e3Sthurlow * SUCH DAMAGE. 314bff34e3Sthurlow * 324bff34e3Sthurlow * $Id: cflib.h,v 1.1.1.1 2001/06/09 00:28:11 zarzycki Exp $ 334bff34e3Sthurlow */ 344bff34e3Sthurlow 35613a2f6bSGordon Ross /* 36613a2f6bSGordon Ross * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 37613a2f6bSGordon Ross * Use is subject to license terms. 38*adee6784SGordon Ross * 39*adee6784SGordon Ross * Copyright 2018 Nexenta Systems, Inc. All rights reserved. 40613a2f6bSGordon Ross */ 414bff34e3Sthurlow 424bff34e3Sthurlow #ifndef _CFLIB_H_ 434bff34e3Sthurlow #define _CFLIB_H_ 444bff34e3Sthurlow 454bff34e3Sthurlow struct rcfile; 464bff34e3Sthurlow 474bff34e3Sthurlow /* 484bff34e3Sthurlow * A unified options parser 494bff34e3Sthurlow */ 504bff34e3Sthurlow enum opt_argtype {OPTARG_STR, OPTARG_INT, OPTARG_BOOL}; 514bff34e3Sthurlow 524bff34e3Sthurlow struct opt_args; 534bff34e3Sthurlow 544bff34e3Sthurlow typedef int opt_callback_t (struct opt_args *); 554bff34e3Sthurlow 564bff34e3Sthurlow #define OPTFL_NONE 0x0000 574bff34e3Sthurlow #define OPTFL_HAVEMIN 0x0001 584bff34e3Sthurlow #define OPTFL_HAVEMAX 0x0002 594bff34e3Sthurlow #define OPTFL_MINMAX NAFL_HAVEMIN | NAFL_HAVEMAX 604bff34e3Sthurlow 614bff34e3Sthurlow struct opt_args { 624bff34e3Sthurlow enum opt_argtype type; 634bff34e3Sthurlow int opt; /* command line option */ 644bff34e3Sthurlow char *name; /* rc file equiv */ 654bff34e3Sthurlow int flag; /* OPTFL_* */ 664bff34e3Sthurlow int ival; /* int/bool values, or max len for str value */ 674bff34e3Sthurlow char *str; /* string value */ 684bff34e3Sthurlow int min; /* min for ival */ 694bff34e3Sthurlow int max; /* max for ival */ 704bff34e3Sthurlow opt_callback_t *fn; /* call back to validate */ 714bff34e3Sthurlow }; 724bff34e3Sthurlow typedef struct opt_args opt_args_t; 734bff34e3Sthurlow 744bff34e3Sthurlow extern int cf_opterr, cf_optind, cf_optopt, cf_optreset; 754bff34e3Sthurlow extern const char *cf_optarg; 76613a2f6bSGordon Ross extern struct rcfile *smb_rc; 774bff34e3Sthurlow 784bff34e3Sthurlow #ifdef __cplusplus 794bff34e3Sthurlow extern "C" { 804bff34e3Sthurlow #endif 814bff34e3Sthurlow 824bff34e3Sthurlow int opt_args_parse(struct rcfile *, struct opt_args *, const char *, 834bff34e3Sthurlow opt_callback_t *); 844bff34e3Sthurlow int opt_args_parseopt(struct opt_args *, int, char *, opt_callback_t *); 854bff34e3Sthurlow 864bff34e3Sthurlow int cf_getopt(int, char * const *, const char *); 87613a2f6bSGordon Ross void cf_opt_lock(void); 88613a2f6bSGordon Ross void cf_opt_unlock(void); 894bff34e3Sthurlow 90*adee6784SGordon Ross char *cf_get_client_uuid(void); 91*adee6784SGordon Ross 924bff34e3Sthurlow int rc_getstringptr(struct rcfile *, const char *, const char *, char **); 934bff34e3Sthurlow int rc_getstring(struct rcfile *, const char *, const char *, size_t, char *); 944bff34e3Sthurlow int rc_getint(struct rcfile *, const char *, const char *, int *); 954bff34e3Sthurlow int rc_getbool(struct rcfile *, const char *, const char *, int *); 964bff34e3Sthurlow 97613a2f6bSGordon Ross int smb_open_rcfile(char *); 98613a2f6bSGordon Ross void smb_close_rcfile(void); 99613a2f6bSGordon Ross 1004bff34e3Sthurlow #ifdef __cplusplus 1014bff34e3Sthurlow } 1024bff34e3Sthurlow #endif 1034bff34e3Sthurlow 1044bff34e3Sthurlow #endif /* _CFLIB_H_ */ 105