LCOV - code coverage report
Current view: top level - lib/util - params.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 7 14 50.0 %
Date: 2021-09-23 10:06:22 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /* -------------------------------------------------------------------------- **
       2             :  * Microsoft Network Services for Unix, AKA., Andrew Tridgell's SAMBA.
       3             :  *
       4             :  * This module Copyright (C) 1990-1998 Karl Auer
       5             :  *
       6             :  * Rewritten almost completely by Christopher R. Hertel
       7             :  * at the University of Minnesota, September, 1997.
       8             :  * This module Copyright (C) 1997-1998 by the University of Minnesota
       9             :  * -------------------------------------------------------------------------- **
      10             :  *
      11             :  * This program is free software; you can redistribute it and/or modify
      12             :  * it under the terms of the GNU General Public License as published by
      13             :  * the Free Software Foundation; either version 3 of the License, or
      14             :  * (at your option) any later version.
      15             :  *
      16             :  * This program is distributed in the hope that it will be useful,
      17             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  * GNU General Public License for more details.
      20             :  *
      21             :  * You should have received a copy of the GNU General Public License
      22             :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      23             :  *
      24             :  * -------------------------------------------------------------------------- **
      25             :  *
      26             :  * Module name: params
      27             :  *
      28             :  * -------------------------------------------------------------------------- **
      29             :  *
      30             :  *  This module performs lexical analysis and initial parsing of a
      31             :  *  Windows-like parameter file.  It recognizes and handles four token
      32             :  *  types:  section-name, parameter-name, parameter-value, and
      33             :  *  end-of-file.  Comments and line continuation are handled
      34             :  *  internally.
      35             :  *
      36             :  *  The entry point to the module is function pm_process().  This
      37             :  *  function opens the source file, calls the Parse() function to parse
      38             :  *  the input, and then closes the file when either the EOF is reached
      39             :  *  or a fatal error is encountered.
      40             :  *
      41             :  *  A sample parameter file might look like this:
      42             :  *
      43             :  *  [section one]
      44             :  *  parameter one = value string
      45             :  *  parameter two = another value
      46             :  *  [section two]
      47             :  *  new parameter = some value or t'other
      48             :  *
      49             :  *  The parameter file is divided into sections by section headers:
      50             :  *  section names enclosed in square brackets (eg. [section one]).
      51             :  *  Each section contains parameter lines, each of which consist of a
      52             :  *  parameter name and value delimited by an equal sign.  Roughly, the
      53             :  *  syntax is:
      54             :  *
      55             :  *    <file>            :==  { <section> } EOF
      56             :  *
      57             :  *    <section>         :==  <section header> { <parameter line> }
      58             :  *
      59             :  *    <section header>  :==  '[' NAME ']'
      60             :  *
      61             :  *    <parameter line>  :==  NAME '=' VALUE '\n'
      62             :  *
      63             :  *  Blank lines and comment lines are ignored.  Comment lines are lines
      64             :  *  beginning with either a semicolon (';') or a pound sign ('#').
      65             :  *
      66             :  *  All whitespace in section names and parameter names is compressed
      67             :  *  to single spaces.  Leading and trailing whitespace is stipped from
      68             :  *  both names and values.
      69             :  *
      70             :  *  Only the first equals sign in a parameter line is significant.
      71             :  *  Parameter values may contain equals signs, square brackets and
      72             :  *  semicolons.  Internal whitespace is retained in parameter values,
      73             :  *  with the exception of the '\r' character, which is stripped for
      74             :  *  historic reasons.  Parameter names may not start with a left square
      75             :  *  bracket, an equal sign, a pound sign, or a semicolon, because these
      76             :  *  are used to identify other tokens.
      77             :  *
      78             :  * -------------------------------------------------------------------------- **
      79             :  */
      80             : 
      81             : #include "replace.h"
      82             : #include "lib/util/samba_util.h"
      83             : #include "tini.h"
      84             : 
      85      187464 : bool pm_process(const char *filename,
      86             :                 bool (*sfunc)(const char *section, void *private_data),
      87             :                 bool (*pfunc)(const char *name, const char *value,
      88             :                               void *private_data),
      89             :                 void *private_data)
      90             : {
      91             :         FILE *f;
      92             :         bool ret;
      93             : 
      94      187464 :         f = fopen(filename, "r");
      95      187464 :         if (f == NULL) {
      96         247 :                 return false;
      97             :         }
      98             : 
      99      187210 :         ret = tini_parse(f, false, sfunc, pfunc, private_data);
     100             : 
     101      187210 :         fclose(f);
     102             : 
     103      187210 :         return ret;
     104             : }
     105             : 
     106             : 
     107           0 : bool pm_process_with_flags(const char *filename,
     108             :                            bool allow_empty_values,
     109             :                            bool (*sfunc)(const char *section, void *private_data),
     110             :                            bool (*pfunc)(const char *name, const char *value,
     111             :                                          void *private_data),
     112             :                            void *private_data)
     113             : {
     114             :         FILE *f;
     115             :         bool ret;
     116             : 
     117           0 :         f = fopen(filename, "r");
     118           0 :         if (f == NULL) {
     119           0 :                 return false;
     120             :         }
     121             : 
     122           0 :         ret = tini_parse(f, allow_empty_values, sfunc, pfunc, private_data);
     123             : 
     124           0 :         fclose(f);
     125             : 
     126           0 :         return ret;
     127             : }

Generated by: LCOV version 1.13