1  /*
2   * Copyright (c) 2018 The Linux Foundation. All rights reserved.
3   * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4   *
5   * Permission to use, copy, modify, and/or distribute this software for
6   * any purpose with or without fee is hereby granted, provided that the
7   * above copyright notice and this permission notice appear in all
8   * copies.
9   *
10   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11   * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12   * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13   * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14   * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15   * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17   * PERFORMANCE OF THIS SOFTWARE.
18   */
19  
20  /**
21   * DOC: Text parsing related abstractions, not related to a specific type
22   */
23  
24  #ifndef __QDF_PARSE_H
25  #define __QDF_PARSE_H
26  
27  #include "qdf_status.h"
28  
29  typedef QDF_STATUS (*qdf_ini_section_cb)(void *context, const char *name);
30  typedef QDF_STATUS (*qdf_ini_item_cb)(void *context,
31  				      const char *key,
32  				      const char *value);
33  
34  /**
35   * qdf_ini_parse() - parse an ini file
36   * @ini_path: The full file path of the ini file to parse
37   * @context: The caller supplied context to pass into callbacks
38   * @item_cb: Ini item (key/value pair) handler callback function
39   *	Return QDF_STATUS_SUCCESS to continue parsing, else to abort
40   * @section_cb: Ini section header handler callback function
41   *	Return QDF_STATUS_SUCCESS to continue parsing, else to abort
42   *
43   * The *.ini file format is a simple format consisting of a list of key/value
44   * pairs (items), separated by an '=' character. Comments are initiated with
45   * a '#' character. Sections are also supported, using '[' and ']' around the
46   * section name. e.g.
47   *
48   *	# comments are started with a '#' character
49   *	# items are key/value string pairs, separated by the '=' character
50   *	someKey1=someValue1
51   *	someKey2=someValue2 # this is also a comment
52   *
53   *	# section headers are enclosed in square brackets
54   *	[some section header] # new section begins
55   *	someKey3=someValue3
56   *
57   * Return: QDF_STATUS
58   */
59  QDF_STATUS
60  qdf_ini_parse(const char *ini_path, void *context,
61  	      qdf_ini_item_cb item_cb, qdf_ini_section_cb section_cb);
62  
63  /**
64   * qdf_ini_section_parse() - parse a section from ini file
65   * @ini_path: The full file path of the ini file to parse
66   * @context: The caller supplied context to pass into callbacks
67   * @item_cb: Ini item (key/value pair) handler callback function
68   *	Return QDF_STATUS_SUCCESS to continue parsing, else to abort
69   * @section_name: Ini section name to be parsed from file
70   *	Return QDF_STATUS_SUCCESS to continue parsing, else to abort
71   *
72   * The *.ini file format is a simple format consisting of a list of key/value
73   * pairs (items), separated by an '=' character. Comments are initiated with
74   * a '#' character. Sections are also supported, using '[' and ']' around the
75   * section name. e.g.
76   *
77   *	# comments are started with a '#' character
78   *	# items are key/value string pairs, separated by the '=' character
79   *	someKey1=someValue1
80   *	someKey2=someValue2 # this is also a comment
81   *
82   *	# section headers are enclosed in square brackets
83   *	[some section header] # new section begins
84   *	someKey3=someValue3
85   *
86   * Return: QDF_STATUS
87   */
88  QDF_STATUS qdf_ini_section_parse(const char *ini_path, void *context,
89  				 qdf_ini_item_cb item_cb,
90  				 const char *section_name);
91  
92  /**
93   * qdf_valid_ini_check() - check ini file for invalid characters
94   * @path: path to ini file
95   *
96   * Return: true if no invalid character found, false otherwise
97   */
98  bool qdf_valid_ini_check(const char *path);
99  
100  #endif /* __QDF_PARSE_H */
101  
102