Commit dc61f8f7 authored by Daniel Kutik's avatar Daniel Kutik Committed by Bjorn Andersson
Browse files

Moved attr_as_unsigned and attr_as_string to util



Moved the two functions to util.c to remove duplicate code.
The previous error handling in some of the implemenations was
incomplete as it caused qdl to crash.
While the variable errors was incremented we still tried to
return the regular result. Now returning 0/NULL in case of error.
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent cfce0bee
......@@ -34,32 +34,11 @@
#include <libxml/tree.h>
#include "patch.h"
#include "qdl.h"
static struct patch *patches;
static struct patch *patches_last;
static unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value)
(*errors)++;
return strtoul((char*)value, NULL, 10);
}
static const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value)
(*errors)++;
return strdup((char*)value);
}
int patch_load(const char *patch_file)
{
struct patch *patch;
......
......@@ -36,46 +36,11 @@
#include <libxml/tree.h>
#include "program.h"
#include "qdl.h"
static struct program *programes;
static struct program *programes_last;
static unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value)
(*errors)++;
return strtoul((char*)value, NULL, 10);
}
static const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value)
(*errors)++;
if (value && value[0] == '\0')
return NULL;
return strdup((char*)value);
}
static bool attr_as_bool(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value)
(*errors)++;
return xmlStrcmp(value, (xmlChar*)"true") == 0;
}
int program_load(const char *program_file)
{
struct program *program;
......
......@@ -5,10 +5,13 @@
#include "patch.h"
#include "program.h"
#include <libxml/tree.h>
int firehose_run(int fd, const char *incdir);
int sahara_run(int fd, char *prog_mbn);
void print_hex_dump(const char *prefix, const void *buf, size_t len);
unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors);
const char *attr_as_string(xmlNode *node, const char *attr, int *errors);
extern bool qdl_debug;
......
......@@ -55,32 +55,7 @@ static const char notice_bconfigdescrlock[] = "\n"
" and don't use command line parameter --finalize-provisioning.\n\n"
"In case of mismatch between CL and XML provisioning is not performed.\n\n";
// ToDo: These 2 functions must be moved to a common module (refactoring required)
static unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value) {
(*errors)++;
return 0;
}
return strtoul((char*)value, NULL, 0);
}
static const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value)
(*errors)++;
if (value && value[0] == '\0')
return NULL;
return strdup((char*)value);
}
bool ufs_need_provisioning(void)
{
......
......@@ -31,6 +31,9 @@
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#define MIN(x, y) ((x) < (y) ? (x) : (y))
......@@ -77,3 +80,32 @@ void print_hex_dump(const char *prefix, const void *buf, size_t len)
printf("%s %04x: %s\n", prefix, i, line);
}
}
unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value) {
(*errors)++;
return 0;
}
return (unsigned int) strtoul((char*)value, NULL, 10);
}
const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
value = xmlGetProp(node, (xmlChar*)attr);
if (!value) {
(*errors)++;
return NULL;
}
if (value[0] == '\0')
return NULL;
return strdup((char*)value);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment