ACK: [PATCH 09/20] fwts_log_scan: move fwts_json_str

Alex Hung alex.hung at canonical.com
Wed Jun 27 22:50:48 UTC 2018


On 2018-06-20 05:14 AM, Marcello Sylvester Bauer wrote:
> Signed-off-by: Marcello Sylvester Bauer <info at marcellobauer.com>
> ---
>   src/lib/include/fwts_klog.h     |  1 -
>   src/lib/include/fwts_log_scan.h |  3 +++
>   src/lib/src/fwts_klog.c         | 35 -----------------------------------
>   src/lib/src/fwts_log_scan.c     | 35 +++++++++++++++++++++++++++++++++++
>   4 files changed, 38 insertions(+), 36 deletions(-)
> 
> diff --git a/src/lib/include/fwts_klog.h b/src/lib/include/fwts_klog.h
> index 0c077b71..933ba455 100644
> --- a/src/lib/include/fwts_klog.h
> +++ b/src/lib/include/fwts_klog.h
> @@ -50,6 +50,5 @@ int        fwts_klog_write(fwts_framework *fw, const char *msg);
>   
>   fwts_compare_mode fwts_klog_compare_mode_str_to_val(const char *str);
>   char *fwts_klog_unique_label(const char *str);
> -const char *fwts_json_str(fwts_framework *fw, const char *table, int index, json_object *obj, const char *key, bool log_error);
>   
>   #endif
> diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h
> index f4ebfc4c..849a9d1b 100644
> --- a/src/lib/include/fwts_log_scan.h
> +++ b/src/lib/include/fwts_log_scan.h
> @@ -22,6 +22,8 @@
>   
>   #include <regex.h>
>   
> +#include "fwts_json.h"
> +
>   typedef enum {
>   	FWTS_COMPARE_REGEX = 'r',
>   	FWTS_COMPARE_STRING = 's',
> @@ -48,5 +50,6 @@ int        fwts_log_scan(fwts_framework *fw, fwts_list *log, fwts_log_scan_func
>   char *fwts_log_unique_label(const char *str, const char *label);
>   void       fwts_log_scan_patterns(fwts_framework *fw, char *line, int repeated, char *prevline, void *private, int *errors, const char *name, const char *advice);
>   fwts_compare_mode fwts_log_compare_mode_str_to_val(const char *str);
> +const char *fwts_json_str(fwts_framework *fw, const char *table, int index, json_object *obj, const char *key, bool log_error);
>   
>   #endif
> diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
> index 159b7541..a0d3b561 100644
> --- a/src/lib/src/fwts_klog.c
> +++ b/src/lib/src/fwts_klog.c
> @@ -129,41 +129,6 @@ fwts_compare_mode fwts_klog_compare_mode_str_to_val(const char *str)
>   	return fwts_log_compare_mode_str_to_val(str);
>   }
>   
> -/*
> - *  fwts_json_str()
> - *	given a key, fetch the string value associated with this object
> - *	and report an error if it cannot be found.
> - */
> -const char *fwts_json_str(
> -	fwts_framework *fw,
> -	const char *table,
> -	int index,
> -	json_object *obj,
> -	const char *key,
> -	bool log_error)
> -{
> -	const char *str;
> -#if JSON_HAS_GET_EX
> -	json_object *str_obj;
> -
> -	if (!json_object_object_get_ex(obj, key, &str_obj))
> -		goto nullobj;
> -	str = json_object_get_string(str_obj);
> -	if (FWTS_JSON_ERROR(str))
> -		goto nullobj;
> -#else
> -	str = json_object_get_string(json_object_object_get(obj, key));
> -	if (FWTS_JSON_ERROR(str))
> -		goto nullobj;
> -#endif
> -	return str;
> -nullobj:
> -	if (log_error)
> -		fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.",
> -			key, index, table);
> -	return NULL;
> -}
> -
>   static int fwts_klog_check(fwts_framework *fw,
>   	const char *table,
>   	fwts_klog_progress_func progress,
> diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c
> index 3146554a..f9ed7b35 100644
> --- a/src/lib/src/fwts_log_scan.c
> +++ b/src/lib/src/fwts_log_scan.c
> @@ -310,3 +310,38 @@ fwts_compare_mode fwts_log_compare_mode_str_to_val(const char *str)
>           else
>                   return FWTS_COMPARE_UNKNOWN;
>   }
> +
> +/*
> + *  fwts_json_str()
> + *	given a key, fetch the string value associated with this object
> + *	and report an error if it cannot be found.
> + */
> +const char *fwts_json_str(
> +	fwts_framework *fw,
> +	const char *table,
> +	int index,
> +	json_object *obj,
> +	const char *key,
> +	bool log_error)
> +{
> +	const char *str;
> +#if JSON_HAS_GET_EX
> +	json_object *str_obj;
> +
> +	if (!json_object_object_get_ex(obj, key, &str_obj))
> +		goto nullobj;
> +	str = json_object_get_string(str_obj);
> +	if (FWTS_JSON_ERROR(str))
> +		goto nullobj;
> +#else
> +	str = json_object_get_string(json_object_object_get(obj, key));
> +	if (FWTS_JSON_ERROR(str))
> +		goto nullobj;
> +#endif
> +	return str;
> +nullobj:
> +	if (log_error)
> +		fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.",
> +			key, index, table);
> +	return NULL;
> +}
> 


Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list