LCOV - code coverage report
Current view: top level - lib/util - params.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 12 12 100.0 %
Date: 2024-04-21 15:09:00 Functions: 2 2 100.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 stripped 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      226781 : 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      226781 :         bool ret = pm_process_with_flags(
      92             :                 filename, false, sfunc, pfunc, private_data);
      93      226781 :         return ret;
      94             : }
      95             : 
      96      226781 : bool pm_process_with_flags(const char *filename,
      97             :                            bool allow_empty_values,
      98             :                            bool (*sfunc)(const char *section, void *private_data),
      99             :                            bool (*pfunc)(const char *name, const char *value,
     100             :                                          void *private_data),
     101             :                            void *private_data)
     102             : {
     103         821 :         FILE *f;
     104         821 :         bool ret;
     105             : 
     106      226781 :         f = fopen(filename, "r");
     107      226781 :         if (f == NULL) {
     108         328 :                 return false;
     109             :         }
     110             : 
     111      226446 :         ret = tini_parse(f, allow_empty_values, sfunc, pfunc, private_data);
     112             : 
     113      226446 :         fclose(f);
     114             : 
     115      226446 :         return ret;
     116             : }

Generated by: LCOV version 1.14