qcacmn: Add context parameter to qdf_ini_parse()

In order to avoid global state, add a context parameter to
qdf_ini_parse. This parameter will get passed back to consumers via
the existing callbacks.

Change-Id: Icd74a58815701b4603924838bb84c7956058da6b
CRs-Fixed: 2194517
This commit is contained in:
Dustin Brown
2018-02-22 15:14:07 -08:00
committed by snandini
parent c729c57e65
commit b067d27d61
2 changed files with 15 additions and 12 deletions

View File

@@ -17,7 +17,7 @@
*/
/**
* DOC: Thin filesystem API abstractions
* DOC: Text parsing related abstractions, not related to a specific type
*/
#ifndef __QDF_PARSE_H
@@ -25,15 +25,21 @@
#include "qdf_status.h"
typedef QDF_STATUS (*qdf_ini_section_cb)(void *context, const char *name);
typedef QDF_STATUS (*qdf_ini_item_cb)(void *context,
const char *key,
const char *value);
/**
* cfg_ini_parse() - parse an ini file
* qdf_ini_parse() - parse an ini file
* @ini_path: The full file path of the ini file to parse
* @context: The caller supplied context to pass into callbacks
* @item_cb: Ini item (key/value pair) handler callback function
* Return QDF_STATUS_SUCCESS to continue parsing, else to abort
* @section_cb: Ini section header handler callback function
* Return QDF_STATUS_SUCCESS to continue parsing, else to abort
*
* The *.ini file format is a simple format consiting of a list of key/value
* The *.ini file format is a simple format consisting of a list of key/value
* pairs (items), separated by an '=' character. Comments are initiated with
* a '#' character. Sections are also supported, using '[' and ']' around the
* section name. e.g.
@@ -50,9 +56,8 @@
* Return: QDF_STATUS
*/
QDF_STATUS
qdf_ini_parse(const char *ini_path,
QDF_STATUS (*item_cb)(const char *key, const char *value),
QDF_STATUS (*section_cb)(const char *name));
qdf_ini_parse(const char *ini_path, void *context,
qdf_ini_item_cb item_cb, qdf_ini_section_cb section_cb);
#endif /* __QDF_PARSE_H */

View File

@@ -24,10 +24,8 @@
#include "qdf_trace.h"
#include "qdf_types.h"
QDF_STATUS
qdf_ini_parse(const char *ini_path,
QDF_STATUS (*item_cb)(const char *key, const char *value),
QDF_STATUS (*section_cb)(const char *name))
QDF_STATUS qdf_ini_parse(const char *ini_path, void *context,
qdf_ini_item_cb item_cb, qdf_ini_section_cb section_cb)
{
QDF_STATUS status;
char *fbuf;
@@ -98,7 +96,7 @@ qdf_ini_parse(const char *ini_path,
* 3) a line containing whitespace
*/
if (value) {
status = item_cb(key, value);
status = item_cb(context, key, value);
if (QDF_IS_STATUS_ERROR(status))
goto free_fbuf;
} else if (key[0] == '[') {
@@ -108,7 +106,7 @@ qdf_ini_parse(const char *ini_path,
qdf_err("Invalid *.ini syntax '%s'", key);
} else {
key[len - 1] = '\0';
status = section_cb(key + 1);
status = section_cb(context, key + 1);
if (QDF_IS_STATUS_ERROR(status))
goto free_fbuf;
}