Skip to content

Commit

Permalink
xml: Read context version into context structure
Browse files Browse the repository at this point in the history
Store the context version that may appear in the XML string into the
context structure.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Jul 12, 2021
1 parent 9f67f70 commit 47982e5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ void iio_context_destroy(struct iio_context *ctx)
free(ctx->devices);
free(ctx->xml);
free(ctx->description);
free(ctx->git_tag);
free(ctx->pdata);
free(ctx);
}
Expand Down
4 changes: 4 additions & 0 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ struct iio_context {
const char *name;
char *description;

unsigned int major;
unsigned int minor;
char *git_tag;

struct iio_device **devices;
unsigned int nb_devices;

Expand Down
37 changes: 32 additions & 5 deletions xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,12 @@ static int iio_populate_xml_context_helper(struct iio_context *ctx, xmlNode *roo

static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
{
const char *description = NULL;
const char *description = NULL, *git_tag = NULL, *content;
struct iio_context *ctx;
long major = 0, minor = 0;
xmlNode *root;
xmlAttr *attr;
char *end;
int err;

root = xmlDocGetRootElement(doc);
Expand All @@ -421,17 +423,42 @@ static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
}

for (attr = root->properties; attr; attr = attr->next) {
if (!strcmp((char *) attr->name, "description"))
description = (const char *)attr->children->content;
else if (strcmp((char *) attr->name, "name"))
content = (const char *) attr->children->content;

if (!strcmp((char *) attr->name, "description")) {
description = content;
} else if (!strcmp((char *) attr->name, "version-major")) {
major = strtol(content, &end, 10);
if (*end != '\0')
IIO_WARNING("invalid format for major version\n");
} else if (!strcmp((char *) attr->name, "version-minor")) {
minor = strtol(content, &end, 10);
if (*end != '\0')
IIO_WARNING("invalid format for minor version\n");
} else if (!strcmp((char *) attr->name, "version-git")) {
git_tag = content;
} else if (strcmp((char *) attr->name, "name")) {
IIO_WARNING("Unknown parameter \'%s\' in <context>\n",
(char *) attr->children->content);
content);
}
}

ctx = iio_context_create_from_backend(&xml_backend, description);
if (!ctx)
return NULL;

if (git_tag) {
ctx->major = major;
ctx->minor = minor;

ctx->git_tag = iio_strdup(git_tag);
if (!ctx->git_tag) {
iio_context_destroy(ctx);
errno = ENOMEM;
return NULL;
}
}

err = iio_populate_xml_context_helper(ctx, root);
if (err) {
iio_context_destroy(ctx);
Expand Down

0 comments on commit 47982e5

Please sign in to comment.